package main

import (
	"context"
	"fmt"
	client "iaun.cn/linux/services/client"
)

type Client struct {
	client.UnimplementedClientServer
}

const secret = "456123"

func (c *Client) Init(ctx context.Context, data *client.InitReq) (*client.SuccessMsg, error) {
	if data.Server.Secret != secret {
		return &client.SuccessMsg{Success: 0, Msg: "wrong secret"}, nil
	}
	registerClient(data)
	return &client.SuccessMsg{Success: 1, Msg: "success"}, nil
}

func (c *Client) Memory(ctx context.Context, data *client.MemoryReq) (*client.SuccessMsg, error) {
	if data.Server.Secret != secret {
		return &client.SuccessMsg{Success: 0, Msg: "wrong secret"}, nil
	}
	addMemory(data)
	fmt.Println("Memory")
	fmt.Println(data)
	return &client.SuccessMsg{Success: 1, Msg: "success"}, nil
}

func (c *Client) Network(ctx context.Context, data *client.NetReq) (*client.SuccessMsg, error) {
	if data.Server.Secret != secret {
		return &client.SuccessMsg{Success: 0, Msg: "wrong secret"}, nil
	}
	fmt.Println("Network")
	fmt.Println(data)
	return &client.SuccessMsg{Success: 1, Msg: "success"}, nil
}

func (c *Client) CPUPercent(ctx context.Context, data *client.CPUReq) (*client.SuccessMsg, error) {
	if data.Server.Secret != secret {
		return &client.SuccessMsg{Success: 0, Msg: "wrong secret"}, nil
	}
	addCPUPercent(data)
	fmt.Println("CPUPercent")
	fmt.Println(data)
	fmt.Println(data.Percent)
	return &client.SuccessMsg{Success: 1, Msg: "success"}, nil
}
