package logisticsCompany

import (
	"context"
	"git.kumo.work/shama/service/client"
	"time"
)

type contact struct {
}

type ContactItem struct {
	Id        int64      `json:"id"`
	Name      string     `json:"name"`
	Sex       string     `json:"sex"`
	Dept      string     `json:"dept"`
	Job       string     `json:"job"`
	Phone     string     `json:"phone"`
	Fax       string     `json:"fax"`
	Email     string     `json:"email"`
	Tel       string     `json:"tel"`
	Info      string     `json:"info"`
	MainFlag  int64      `json:"mainFlag"`
	CreatedAt *time.Time `json:"createdAt"`
	UpdatedAt *time.Time `json:"updatedAt"`
}

// All @TITLE 获取联系人
func (c *contact) All(ctx context.Context, logisticsCompanyId int64) (reply []ContactItem, err error) {
	xClient, err := client.GetClient(c)
	if err != nil {
		return
	}
	err = xClient.Call(ctx, "All", logisticsCompanyId, &reply)
	return
}

type ArgsContactAdd struct {
	LogisticsCompanyId int64 // 物流公司ID
	ContactAdd
}

type ContactAdd struct {
	Name     string // 联系人姓名
	Sex      string // 性别
	Dept     string // 部门
	Job      string // 职位
	Phone    string // 电话
	Fax      string // 传真
	Email    string // 邮箱
	Tel      string // 移动电话
	Info     string // 联系人备注
	MainFlag int64  // 主联系人 1=主联系人
}

// Add @TITLE 添加联系人
func (c *contact) Add(ctx context.Context, args ArgsContactAdd) (err error) {
	xClient, err := client.GetClient(c)
	if err != nil {
		return
	}
	reply := 0
	return xClient.Call(ctx, "Add", args, &reply)
}

type ArgsContactEdit struct {
	ContactId int64 // 联系人ID
	ContactAdd
}

// Edit @TITLE 编辑联系人
func (c *contact) Edit(ctx context.Context, args ArgsContactEdit) (err error) {
	xClient, err := client.GetClient(c)
	if err != nil {
		return
	}
	reply := 0
	return xClient.Call(ctx, "Edit", args, &reply)
}

// Delete @TITLE 删除联系人
func (c *contact) Delete(ctx context.Context, contactIds []int64) (err error) {
	xClient, err := client.GetClient(c)
	if err != nil {
		return
	}
	reply := 0
	return xClient.Call(ctx, "Delete", contactIds, &reply)
}