package dto

import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
)

type CreditAccountItem struct {
	CreditAccountId           int     `json:"creditAccountId,string"`    // 账期结算单ID
	ActuallyPaidAmount        float64 `json:"actuallyPaidAmount"`        // 账期结算实付金额
	CreditAccountOrderNum     string  `json:"creditAccountOrderNum"`     // 账期结算单号
	PaymentStatus             int     `json:"paymentStatus"`             // 账期结算支付状态,1待支付,2已支付
	PaymentTime               int64   `json:"paymentTime"`               // 共创账期结算支付时间
	SettlementAmount          float64 `json:"settlementAmount"`          // 账期结算金额
	SettlementTime            int64   `json:"settlementTime"`            // 共创账期结算时间
	CooperationContractNumber string  `json:"cooperationContractNumber"` // 关联共创合约编号
	Participator              struct {
		UserName  string `json:"userName"`  // 用户姓名
		UserPhone string `json:"userPhone"` // 用户手机号
		UserType  int    `json:"userType"`  // 用户类型,1员工,2共创用户,3公开
	} `json:"participator"` // 参与人
	ParticipateType           string             `json:"participateType"`           // 参与类型
	PaymentDocumentAttachment domain.Attachment  `json:"paymentDocumentAttachment"` // 支付凭证附件
	Org                       domain.Org         `json:"org"`                       // 数据所属组织机构
	Company                   domain.CompanyData `json:"company"`                   // 公司
	CreatedAt                 int64              `json:"createdAt"`                 // 创建时间
	UpdatedAt                 int64              `json:"updatedAt"`                 // 更新时间
	AccountDetail             []struct {
		DividendsEstimateOrderNumber string  `json:"dividendsEstimateOrderNumber"`
		DividendsType                int     `json:"dividendsType"`
		DividendsAmount              float64 `json:"dividendsAmount"`
	} `json:"accountDetail"` //结算明细
	Operator struct {
		UserId     int    `json:"userId,string,"`     // 用户ID,
		UserBaseId int    `json:"userBaseId,string,"` // 用户基本id
		UserName   string `json:"userName"`           // 用户姓名
		UserPhone  string `json:"userPhone"`          // 用户手机号
		UserInfo   struct {
			UserName    string `json:"userName"`    // 共创人员姓名
			UserPhone   string `json:"userPhone"`   // 用户手机号
			UserAccount string `json:"userAccount"` // 用户账号,
		} `json:"userInfo"`
	} `json:"operator"`
}

func ToCreditAccountItem(param *allied_creation_cooperation.CreditAccount) *CreditAccountItem {
	data := CreditAccountItem{
		CreditAccountId:           param.CreditAccountId,
		ActuallyPaidAmount:        param.ActuallyPaidAmount,
		CreditAccountOrderNum:     param.CreditAccountOrderNum,
		PaymentStatus:             param.PaymentStatus,
		PaymentTime:               param.PaymentTime.UnixNano() / 1e6,
		SettlementAmount:          param.SettlementAmount,
		SettlementTime:            param.SettlementTime.UnixNano() / 1e6,
		CooperationContractNumber: param.CooperationContractNumber,
		ParticipateType:           param.ParticipateType,            // 参与类型
		PaymentDocumentAttachment: param.PaymentDocumentAttachment,  // 支付凭证附件
		Org:                       param.Org,                        // 数据所属组织机构
		Company:                   param.Company,                    // 公司
		CreatedAt:                 param.CreatedAt.UnixNano() / 1e6, // 创建时间
		UpdatedAt:                 param.UpdatedAt.UnixNano() / 1e6, // 更新时间
		AccountDetail:             param.AccountDetail,
	}
	data.Participator.UserName = param.Participator.UserName
	data.Participator.UserPhone = param.Participator.UserPhone
	data.Participator.UserType = param.Participator.UserType
	data.Operator.UserId = param.Operator.UserId
	data.Operator.UserBaseId = param.Operator.UserBaseId
	data.Operator.UserName = param.Operator.UserName
	data.Operator.UserPhone = param.Operator.UserPhone
	data.Operator.UserInfo.UserName = param.Operator.UserName
	data.Operator.UserInfo.UserPhone = param.Operator.UserPhone
	return &data
}