package erp

import (
	"context"
	client2 "git.kumo.work/shama/service/client"
	logisticsCompany2 "git.kumo.work/shama/service/erp/logisticsCompany"
	"git.kumo.work/shama/service/lib/bean"
	"time"
)

type logisticsCompany struct {
	logisticsCompany2.LogisticsCompany
}
type ArgsLogisticsCompanyList struct {
	Page   bean.Page
	Search LogisticsCompanySearch
}
type LogisticsCompanySearch struct {
	Name            string     // 公司名称
	CreatedStaffIds []int64    // 业务员
	CreatedAtStart  *time.Time // 录入开始时间
	CreatedAtEnd    *time.Time // 录入结束时间
}
type ReplyLogisticsCompanyList struct {
	List  []LogisticsCompanyItem `json:"list"`
	Total int64                  `json:"total"`
}

type LogisticsCompanyItem struct {
	Id             int64      `json:"id"`
	Name           string     `json:"name"`         // 公司名称
	NameEn         string     `json:"nameEn"`       // 公司名称英文
	ShortName      string     `json:"shortName"`    // 公司简称
	City           string     `json:"city"`         // 所在城市
	Type           string     `json:"type"`         // 公司类别
	Address        string     `json:"address"`      // 公司地址
	AddressEn      string     `json:"addressEn"`    // 公司地址
	ZipCode        string     `json:"zipCode"`      // 公司邮编
	TeamRank       string     `json:"teamRank"`     // 合作等级
	Website        string     `json:"website"`      // 网址
	Bank           string     `json:"bank"`         // 开户银行
	BankAccount    string     `json:"bankAccount"`  // 银行账户
	TaxNumber      string     `json:"taxNumber"`    // 税号
	Info           string     `json:"info"`         // 备注说明
	ImgFilePaths   []string   `json:"imgFilePaths"` // 图片地址集合
	CreatedStaffId int64      `json:"createdStaffId"`
	CreatedAt      *time.Time `json:"createdAt"`
	UpdatedAt      *time.Time `json:"updatedAt"`
}

// List @TITLE 客户列表
func (l *logisticsCompany) List(ctx context.Context, args ArgsLogisticsCompanyList) (reply ReplyLogisticsCompanyList, err error) {
	xClient, err := client2.GetClient(l)
	if err != nil {
		return
	}
	err = xClient.Call(ctx, "List", args, &reply)
	return
}

type ArgsLogisticsCompanyAdd struct {
	StaffId int64
	LogisticsCompanyAdd
}

type LogisticsCompanyAdd struct {
	Serial       string   // 编号
	Name         string   // 名称
	NameEn       string   // 名称英文
	ShortName    string   // 公司简称【亿星字段】
	City         string   // 所在城市【亿星字段】
	Type         string   // 公司类别【亿星字段】
	Address      string   // 公司地址
	AddressEn    string   // 公司地址英文
	ZipCode      string   // 公司邮编
	TeamRank     string   // 合作等级
	Website      string   // 公司主页
	Bank         string   // 开户银行
	BankAccount  string   // 银行账户
	TaxNumber    string   // 公司税号
	Info         string   // 备注说明
	ImgFilePaths []string // 图片地址集合
}

// Add @TITLE 添加客户
func (l *logisticsCompany) Add(ctx context.Context, args ArgsLogisticsCompanyAdd) (logisticsCompanyId int64, err error) {
	xClient, err := client2.GetClient(l)
	if err != nil {
		return
	}
	err = xClient.Call(ctx, "Add", args, &logisticsCompanyId)
	return
}

type ReplyLogisticsCompanyInfo struct {
	Id             int64      `json:"id"`
	Name           string     `json:"name"`         // 公司名称
	NameEn         string     `json:"nameEn"`       // 公司名称英文
	ShortName      string     `json:"shortName"`    // 公司简称
	City           string     `json:"city"`         // 所在城市
	Type           string     `json:"type"`         // 公司类别
	Address        string     `json:"address"`      // 公司地址
	AddressEn      string     `json:"addressEn"`    // 公司地址
	ZipCode        string     `json:"zipCode"`      // 公司邮编
	TeamRank       string     `json:"teamRank"`     // 合作等级
	Website        string     `json:"website"`      // 网址
	Bank           string     `json:"bank"`         // 开户银行
	BankAccount    string     `json:"bankAccount"`  // 银行账户
	TaxNumber      string     `json:"taxNumber"`    // 税号
	Info           string     `json:"info"`         // 备注说明
	ImgFilePaths   []string   `json:"imgFilePaths"` // 图片地址集合
	CreatedStaffId int64      `json:"createdStaffId"`
	CreatedAt      *time.Time `json:"createdAt"`
	UpdatedAt      *time.Time `json:"updatedAt"`
}

// Info @TITLE 客户详情
func (l *logisticsCompany) Info(ctx context.Context, logisticsCompanyId int64) (reply ReplyLogisticsCompanyInfo, err error) {
	xClient, err := client2.GetClient(l)
	if err != nil {
		return
	}
	err = xClient.Call(ctx, "Info", logisticsCompanyId, &reply)
	return
}

type ArgsLogisticsCompanyEdit struct {
	LogisticsCompanyId int64
	LogisticsCompanyAdd
}

// Edit @TITLE 编辑客户
func (l *logisticsCompany) Edit(ctx context.Context, args ArgsLogisticsCompanyEdit) (err error) {
	xClient, err := client2.GetClient(l)
	if err != nil {
		return
	}
	reply := 0
	return xClient.Call(ctx, "Edit", args, &reply)
}