package fms

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

// ContractPaymentServiceAmount 到款登记-套餐金额分配表
type ContractPaymentServiceAmount struct {
	ContractPaymentServiceAmountId int       `gorm:"primaryKey;column:contract_payment_service_amount_id" json:"contract_payment_service_amount_id"`
	ContractRegisterId             int       `gorm:"column:contract_register_id" json:"contract_register_id" description:"合同登记ID"`
	ContractPaymentId              int       `gorm:"column:contract_payment_id" json:"contract_payment_id" description:"到款登记ID"`
	ServiceTemplateId              int       `gorm:"column:service_template_id" json:"service_template_id" description:"套餐ID"`
	ServiceTemplatePid             int       `gorm:"column:service_template_pid" json:"service_template_pid" description:"套餐父级ID"`
	Amount                         float64   `gorm:"column:amount" json:"amount" description:"分配金额"`
	IsDeleted                      int       `gorm:"column:is_deleted" json:"is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
	InitType                       int       `gorm:"column:init_type" json:"init_type" 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:"最后更新时间"`
}

// ContractPaymentServiceAmountItem 到款套餐分配信息
type ContractPaymentServiceAmountItem struct {
	ContractPaymentServiceAmountId int     `json:"contract_payment_service_amount_id"`
	ContractPaymentId              int     `json:"contract_payment_id" description:"到款登记ID"`
	ServiceTemplateId              int     `json:"service_template_id" description:"套餐ID"`
	ServiceTemplatePid             int     `json:"service_template_pid" description:"套餐父级ID"`
	ServiceTemplateName            string  `json:"service_template_name"`
	Amount                         float64 `json:"amount" description:"分配金额"`
	ServiceProductId               int     `json:"service_product_id" description:"套餐类型：1ficc套餐，2权益套餐"`
}

// DistributePaymentServiceAmountReq 到款登记-分配套餐金额请求体
type DistributePaymentServiceAmountReq struct {
	ContractRegisterId int                                   `json:"contract_register_id" binding:"required,gte=1" description:"合同登记ID"`
	ContractPaymentId  int                                   `json:"contract_payment_id" binding:"required,gte=1" description:"到款登记ID"`
	List               []*DistributePaymentServiceAmountItem `json:"list"`
}

// GetPaymentServiceAmountReq 到款登记-查询分配套餐金额请求体
type GetPaymentServiceAmountReq struct {
	ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"合同登记ID"`
	ContractPaymentId  int `json:"contract_payment_id" binding:"required,gte=1" description:"到款登记ID"`
}

// DistributePaymentServiceAmountItem 到款登记-分配套餐金额列表信息
type DistributePaymentServiceAmountItem struct {
	ContractPaymentServiceAmountId int     `json:"contract_payment_service_amount_id"`
	ServiceTemplateId              int     `json:"service_template_id" description:"套餐ID"`
	ServiceTemplatePid             int     `json:"service_template_pid" description:"套餐父级ID"`
	Amount                         float64 `json:"amount" description:"分配金额"`
}

func (c *ContractPaymentServiceAmount) List(condition string, pars []interface{}) (list []*ContractPaymentServiceAmount, err error) {
	list = make([]*ContractPaymentServiceAmount, 0)
	o := orm.NewOrmUsingDB("fms")
	sql := `SELECT * FROM contract_payment_service_amount  WHERE 1=1 AND is_deleted = 0 `
	sql += condition
	_,err = o.Raw(sql, pars).QueryRows(&list)


	return
}