package dto

import (
	"time"

	"go-admin/app/admin/models"
	"go-admin/common/dto"
	common "go-admin/common/models"
	statuscode "go-admin/common/status_code"

	"github.com/shopspring/decimal"
)

type MemberWithdrawalLogGetPageReq struct {
	dto.Pagination `search:"-"`
	NetworkName    string `form:"networkName"  search:"type:contains;column:network_name;table:member_withdrawal_log" comment:"网络名称"`
	Status         string `form:"status"  search:"type:exact;column:status;table:member_withdrawal_log" comment:"提现状态(member_withdrawal_status)"`
	MemberWithdrawalLogOrder
}

type MemberWithdrawalLogGetPageAppReq struct {
	dto.Pagination `search:"-"`
	NetworkName    string `form:"networkName"  search:"type:contains;column:network_name;table:member_withdrawal_log" comment:"网络名称"`
	Status         string `form:"status"  search:"type:exact;column:status;table:member_withdrawal_log" comment:"提现状态(member_withdrawal_status)"`
	UserId         int    `form:"userId" search:"type:exact;column:user_id;table:member_withdrawal_log" comment:"用户id"`

	MemberWithdrawalLogOrder
}

func (m *MemberWithdrawalLogGetPageAppReq) GetNeedSearch() interface{} {
	return *m
}

type MemberWithdrawalLogOrder struct {
	Id          string `form:"idOrder"  search:"type:order;column:id;table:member_withdrawal_log"`
	NetworkId   string `form:"networkIdOrder"  search:"type:order;column:network_id;table:member_withdrawal_log"`
	NetworkName string `form:"networkNameOrder"  search:"type:order;column:network_name;table:member_withdrawal_log"`
	UserId      string `form:"userIdOrder"  search:"type:order;column:user_id;table:member_withdrawal_log"`
	Amount      string `form:"amountOrder"  search:"type:order;column:amount;table:member_withdrawal_log"`
	Status      string `form:"statusOrder"  search:"type:order;column:status;table:member_withdrawal_log"`
	ConfirmTime string `form:"confirmTimeOrder"  search:"type:order;column:confirm_time;table:member_withdrawal_log"`
	Fee         string `form:"feeOrder"  search:"type:order;column:fee;table:member_withdrawal_log"`
	Remark      string `form:"remarkOrder"  search:"type:order;column:remark;table:member_withdrawal_log"`
	CreatedAt   string `form:"createdAtOrder"  search:"type:order;column:created_at;table:member_withdrawal_log"`
	UpdatedAt   string `form:"updatedAtOrder"  search:"type:order;column:updated_at;table:member_withdrawal_log"`
	DeletedAt   string `form:"deletedAtOrder"  search:"type:order;column:deleted_at;table:member_withdrawal_log"`
	CreateBy    string `form:"createByOrder"  search:"type:order;column:create_by;table:member_withdrawal_log"`
	UpdateBy    string `form:"updateByOrder"  search:"type:order;column:update_by;table:member_withdrawal_log"`
}

func (m *MemberWithdrawalLogGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type MemberWithdrawalLogInsertReq struct {
	Id          int             `json:"-" comment:"主键"` // 主键
	NetworkId   int             `json:"networkId" comment:"网络id"`
	NetworkName string          `json:"networkName" comment:"网络名称"`
	UserId      int             `json:"userId" comment:"用户id"`
	Amount      decimal.Decimal `json:"amount" comment:"提现金额(U)"`
	Status      string          `json:"status" comment:"提现状态(member_withdrawal_status)"`
	ConfirmTime *time.Time      `json:"confirmTime" comment:"确认时间"`
	Fee         decimal.Decimal `json:"fee" comment:"手续费比例"`
	Remark      string          `json:"remark" comment:"备注"`
	common.ControlBy
}

func (s *MemberWithdrawalLogInsertReq) Generate(model *models.MemberWithdrawalLog) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.NetworkId = s.NetworkId
	model.NetworkName = s.NetworkName
	model.UserId = s.UserId
	model.Amount = s.Amount
	model.Status = s.Status
	model.ConfirmTime = s.ConfirmTime
	model.Fee = s.Fee
	model.Remark = s.Remark
	model.CreateBy = s.CreateBy // 添加这而，需要记录是被谁创建的
}

func (s *MemberWithdrawalLogInsertReq) GetId() interface{} {
	return s.Id
}

type MemberWithdrawalLogUpdateReq struct {
	Id          int             `uri:"id" comment:"主键"` // 主键
	NetworkId   int             `json:"networkId" comment:"网络id"`
	NetworkName string          `json:"networkName" comment:"网络名称"`
	UserId      int             `json:"userId" comment:"用户id"`
	Amount      decimal.Decimal `json:"amount" comment:"提现金额(U)"`
	Status      string          `json:"status" comment:"提现状态(member_withdrawal_status)"`
	ConfirmTime *time.Time      `json:"confirmTime" comment:"确认时间"`
	Fee         decimal.Decimal `json:"fee" comment:"手续费比例"`
	Remark      string          `json:"remark" comment:"备注"`
	common.ControlBy
}

func (s *MemberWithdrawalLogUpdateReq) Generate(model *models.MemberWithdrawalLog) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.NetworkId = s.NetworkId
	model.NetworkName = s.NetworkName
	model.UserId = s.UserId
	model.Amount = s.Amount
	model.Status = s.Status
	model.ConfirmTime = s.ConfirmTime
	model.Fee = s.Fee
	model.Remark = s.Remark
	model.UpdateBy = s.UpdateBy // 添加这而，需要记录是被谁更新的
}

func (s *MemberWithdrawalLogUpdateReq) GetId() interface{} {
	return s.Id
}

// MemberWithdrawalLogGetReq 功能获取请求参数
type MemberWithdrawalLogGetReq struct {
	Id int `uri:"id"`
}

func (s *MemberWithdrawalLogGetReq) GetId() interface{} {
	return s.Id
}

// MemberWithdrawalLogDeleteReq 功能删除请求参数
type MemberWithdrawalLogDeleteReq struct {
	Ids []int `json:"ids"`
}

func (s *MemberWithdrawalLogDeleteReq) GetId() interface{} {
	return s.Ids
}

type MemberWithdrawalLogCancelReq struct {
	Id int `json:"id"`
}

func (s *MemberWithdrawalLogCancelReq) Valid() int {
	if s.Id <= 0 {
		return statuscode.ParamErr
	}

	return statuscode.OK
}

type MemberWithdrawalLogApplyReq struct {
	NetworkId int             `json:"networkId" comment:"网络ID"`
	UserId    int             `json:"userId" comment:"用户ID"`
	Amount    decimal.Decimal `json:"amount" comment:"提现金额"`
	ToAddress string          `json:"toAddress" comment:"提现地址"`
}

func (e *MemberWithdrawalLogApplyReq) Valid() int {
	if e.NetworkId <= 0 {
		return statuscode.ParamErr
	}

	if e.Amount.Cmp(decimal.Zero) <= 0 {
		return statuscode.ParamErr
	}

	if e.ToAddress == "" {
		return statuscode.ParamErr
	}
	return statuscode.OK
}

type MemberWithdrawalLogResp struct {
	Id              int             `json:"id"`
	NetworkId       int             `json:"networkId"`
	NetworkName     string          `json:"networkName"`
	UserId          int             `json:"userId"`
	NickName        string          `json:"nickName"`
	Amount          decimal.Decimal `json:"amount"`
	Fee             decimal.Decimal `json:"fee"`
	ToAddress       string          `json:"toAddress"`
	Hash            string          `json:"hash"`
	Status          string          `json:"status"`
	CreateTimeUnix  int64           `json:"createTime"`
	ConfirmTimeUnix int64           `json:"confirmTime"`
	Remark          string          `json:"remark"`
}

type MemberWithdrawalLogApprovedReq struct {
	Id       int    `json:"id"`
	Approval int    `json:"approval"` // 1:通过 2:拒绝
	Remark   string `json:"remark" comment:"备注" `
}

type MemberWithdrawalLogConfirmReq struct {
	Id         int    `json:"id"`
	ConfirmVal int    `json:"confirmVal"` // 1:成功 2:失败
	Remark     string `json:"remark"`
	Hash       string `json:"hash"` //交易hash
}
