package fms

import (
	"time"
)

// ContractRegister 合同登记表
type ContractRegister struct {
	ContractRegisterId     int       `gorm:"primaryKey;column:contract_register_id" json:"contract_register_id" description:"登记ID"`
	ContractCode           string    `gorm:"column:contract_code" json:"contract_code" description:"合同编号"`
	RelateContractCode     string    `gorm:"column:relate_contract_code" json:"relate_contract_code" description:"关联合同编号"`
	RelateContractMainCode string    `gorm:"column:relate_contract_main_code" json:"relate_contract_main_code" description:"关联主合同编号"`
	CrmContractId          int       `gorm:"column:crm_contract_id" json:"crm_contract_id" description:"CRM系统-合同ID"`
	ContractSource         int       `gorm:"column:contract_source" json:"contract_source" description:"合同来源: 0-非系统合同导入; 1-CRM合同导入"`
	CompanyName            string    `gorm:"column:company_name" json:"company_name" description:"客户名称"`
	ActualCompanyName      string    `gorm:"column:actual_company_name" json:"actual_company_name" description:"实际使用方"`
	ProductIds             string    `gorm:"column:product_ids" json:"product_ids" description:"产品ID：1-FICC; 2-权益, 如果两者都有，则用英文逗号拼接"`
	SellerId               int       `gorm:"column:seller_id" json:"seller_id" description:"CRM系统-销售ID"`
	SellerName             string    `gorm:"column:seller_name" json:"seller_name" description:"CRM系统-销售名称"`
	RaiSellerId            int       `gorm:"column:rai_seller_id" json:"rai_seller_id"  description:"CRM系统-权益销售ID"`
	RaiSellerName          string    `gorm:"column:rai_seller_name" json:"rai_seller_name" description:"CRM系统-权益销售名称"`
	ContractType           int       `gorm:"column:contract_type" json:"contract_type" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
	ContractAmount         float64   `gorm:"column:contract_amount" json:"contract_amount" description:"合同金额"`
	InvoicedAmount         float64   `gorm:"column:invoiced_amount" json:"invoiced_amount" description:"开票金额"`
	PaymentAmount          float64   `gorm:"column:payment_amount" json:"payment_amount" description:"到款金额"`
	CurrencyUnit           string    `gorm:"column:currency_unit" json:"currency_unit" description:"货币国际代码"`
	RMBRate                float64   `gorm:"column:rmb_rate" json:"rmb_rate" description:"人民币汇率(create_time当日)"`
	StartDate              time.Time `gorm:"column:start_date" json:"start_date" description:"合同开始日期"`
	EndDate                time.Time `gorm:"column:end_date" json:"end_date" description:"合同结束日期"`
	SignDate               time.Time `gorm:"column:sign_date" json:"sign_date" description:"合同签订日期"`
	AgreedPayTime          string    `gorm:"column:agreed_pay_time" json:"agreed_pay_time" description:"约定付款时间(如:生效日起10日内)"`
	ContractStatus         int       `gorm:"column:contract_status" json:"contract_status" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回"`
	RegisterStatus         int       `gorm:"column:register_status" json:"register_status" description:"登记状态: 1-进行中; 2-已完成;"`
	Remark                 string    `gorm:"column:remark" json:"remark" description:"备注信息"`
	ServiceRemark          string    `gorm:"column:service_remark" json:"service_remark" description:"套餐备注信息"`
	HasPayment             int       `gorm:"column:has_payment" json:"has_payment" description:"是否有代付: 0-无; 1-有"`
	HasInvoice             int       `gorm:"column:has_invoice" json:"has_invoice" description:"是否需要开票到款: 0-无; 1-有"`
	NewCompany             int       `gorm:"column:new_company" json:"new_company" description:"是否为新客户: 0-否; 1-是"`
	ActualPayCompanies string    `gorm:"column:actual_pay_companies" json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
	IsDeleted              int       `gorm:"column:is_deleted" json:"is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
	CreateTime time.Time `gorm:"autoCreateTime;column:create_time" json:"create_time" description:"创建时间"`
	ModifyTime time.Time `gorm:"autoUpdateTime:milli;column:modify_time" json:"modify_time" description:"最后更新时间"`
}

// ContractRegisterItem 合同登记
type ContractRegisterItem struct {
	ContractRegisterId int     `json:"contract_register_id" description:"登记ID"`
	ContractCode       string  `json:"contract_code" description:"合同编号"`
	RelateContractCode string  `json:"relate_contract_code" description:"关联合同编号"`
	CrmContractId      int     `json:"crm_contract_id" description:"CRM系统-合同ID"`
	ContractSource     int     `json:"contract_source" description:"合同来源: 0-非系统合同导入; 1-CRM合同导入"`
	CompanyName        string  `json:"company_name" description:"客户名称"`
	ActualCompanyName  string  `json:"actual_company_name" description:"实际使用方"`
	ProductIds         string  `json:"product_ids" description:"产品ID：1-FICC; 2-权益, 如果两者都有，则用英文逗号拼接"`
	SellerId           int     `json:"seller_id" description:"CRM系统-销售ID"`
	SellerName         string  `json:"seller_name" description:"CRM系统-销售名称"`
	RaiSellerId        int     `json:"rai_seller_id"  description:"CRM系统-权益销售ID"`
	RaiSellerName      string  `json:"rai_seller_name" description:"CRM系统-权益销售名称"`
	ContractType       int     `json:"contract_type" description:"合同类型: 1-新签; 2-续约"`
	ContractAmount     float64 `json:"contract_amount" description:"合同金额"`
	InvoicedAmount     float64 `json:"invoiced_amount" description:"开票金额"`
	PaymentAmount      float64 `json:"payment_amount" description:"到款金额"`
	CurrencyUnit       string  `json:"currency_unit" description:"货币国际代码"`
	RMBRate            float64 `json:"rmb_rate" description:"人民币汇率(create_time当日)"`
	StartDate          string  `json:"start_date" description:"合同开始日期"`
	EndDate            string  `json:"end_date" description:"合同结束日期"`
	SignDate           string  `json:"sign_date" description:"合同签订日期"`
	AgreedPayTime      string  `json:"agreed_pay_time" description:"约定付款时间(如:生效日起10日内)"`
	ContractStatus     int     `json:"contract_status" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回"`
	RegisterStatus     int     `json:"register_status" description:"登记状态: 1-进行中; 2-已完成;"`
	Remark             string  `json:"remark" description:"备注信息"`
	ServiceRemark      string  `json:"service_remark" description:"套餐备注信息"`
	HasPayment         int     `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
	HasInvoice         int     `json:"has_invoice" description:"是否需要开票到款: 0-无; 1-有"`
	NewCompany         int     `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
	ActualPayCompanies string  `json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
	CreateTime         string  `json:"create_time" description:"登记时间"`
	SellerIds          string  `json:"seller_ids"`
}

// ContractRegisterList 合同登记列表
type ContractRegisterList struct {
	*ContractRegisterItem
	ContractTypeString string                 `json:"contract_type_string" description:"合同类型"`
	ServicesName       string                 `json:"services" description:"套餐名称"`
	InvoiceList        []*ContractInvoiceItem `json:"invoice_list" description:"开票信息"`
	PaymentList        []*ContractInvoiceItem `json:"payment_list" description:"到款信息"`
}

// ContractRegisterDelReq 合同登记-删除请求体
type ContractRegisterDelReq struct {
	ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"登记ID"`
}

// ContractRegisterUpdateStatusReq 合同登记-修改合同状态请求体
type ContractRegisterUpdateStatusReq struct {
	ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"登记ID"`
	ContractStatus     int `json:"contract_status" binding:"oneof=1 2 3 4 5" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回; 4-已终止， 5-邮件备案"`
}

// ContractRegisterDetailReq 合同登记-详情请求体
type ContractRegisterDetailReq struct {
	ContractRegisterId int `json:"contract_register_id" form:"contract_register_id" binding:"required,gte=1"`
}


type CheckContractNameReq struct {
	CompanyName string `json:"company_name" form:"company_name" description:"客户名称"`
	StartDate   string `json:"start_date" form:"start_date" description:"合同开始日期"`
	EndDate     string `json:"end_date" form:"end_date" description:"合同结束日期"`
	SellerIds   string `json:"seller_ids" form:"seller_ids" binding:"required" description:"CRM系统-销售ID"`
}

type CheckContractNameResp struct {
	Exist int `json:"exist" description:"是否存在相似的合同：0不存在，1存在"`
}


type CheckContractDuplicateResp struct {
	Exist int `json:"exist" description:"是否存在重复的合同：0不存在，1存在"`
}
