package dto

import (
	"cold-delivery/common/dto"
	common "cold-delivery/common/model"
	"time"

	"cold-delivery/app/admin/model"
)

const (
	OperaStatusEnabel  = "1" // 状态-正常
	OperaStatusDisable = "2" // 状态-关闭
)

type SysOperaLogGetPageReq struct {
	dto.Pagination `search:"-"`
	Title          string `form:"title" search:"type:contains;column:title;table:sys_opera_log" comment:"操作模块"`
	Method         string `form:"method" search:"type:contains;column:method;table:sys_opera_log" comment:"函数"`
	RequestMethod  string `form:"requestMethod" search:"type:contains;column:request_method;table:sys_opera_log" comment:"请求方式: GET POST PUT DELETE"`
	OperaUrl       string `form:"operaUrl" search:"type:contains;column:opera_url;table:sys_opera_log" comment:"访问地址"`
	OperaIp        string `form:"operaIp" search:"type:exact;column:opera_ip;table:sys_opera_log" comment:"客户端ip"`
	Status         int    `form:"status" search:"type:exact;column:status;table:sys_opera_log" comment:"状态 1:正常 2:关闭"`
	BeginTime      string `form:"beginTime" search:"type:gte;column:created_at;table:sys_opera_log" comment:"创建时间"`
	EndTime        string `form:"endTime" search:"type:lte;column:created_at;table:sys_opera_log" comment:"更新时间"`
	SysOperaLogOrder
}

type SysOperaLogOrder struct {
	CreatedAtOrder string `search:"type:order;column:created_at;table:sys_opera_log" form:"createdAtOrder"`
}

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

type SysOperaLogControl struct {
	ID            int       `uri:"Id" comment:"编码"` // 编码
	Title         string    `json:"title" comment:"操作模块"`
	BusinessType  string    `json:"businessType" comment:"操作类型"`
	BusinessTypes string    `json:"businessTypes" comment:""`
	Method        string    `json:"method" comment:"函数"`
	RequestMethod string    `json:"requestMethod" comment:"请求方式"`
	OperatorType  string    `json:"operatorType" comment:"操作类型"`
	OperaName     string    `json:"operaName" comment:"操作者"`
	DeptName      string    `json:"organName" comment:"机构名称"`
	OperaUrl      string    `json:"operaUrl" comment:"访问地址"`
	OperaIp       string    `json:"operaIp" comment:"客户端ip"`
	OperaLocation string    `json:"operaLocation" comment:"访问位置"`
	OperaParam    string    `json:"operaParam" comment:"请求参数"`
	Status        string    `json:"status" comment:"操作状态"`
	OperaTime     time.Time `json:"operaTime" comment:"操作时间"`
	JsonResult    string    `json:"jsonResult" comment:"返回数据"`
	Remark        string    `json:"remark" comment:"备注"`
	LatencyTime   string    `json:"latencyTime" comment:"耗时"`
	UserAgent     string    `json:"userAgent" comment:"ua"`
}

func (s *SysOperaLogControl) Generate() (*model.SysOperaLog, error) {
	return &model.SysOperaLog{
		Model:         common.Model{Id: s.ID},
		Title:         s.Title,
		BusinessType:  s.BusinessType,
		BusinessTypes: s.BusinessTypes,
		Method:        s.Method,
		RequestMethod: s.RequestMethod,
		OperatorType:  s.OperatorType,
		OperaName:     s.OperaName,
		DeptName:      s.DeptName,
		OperaUrl:      s.OperaUrl,
		OperaIp:       s.OperaIp,
		OperaLocation: s.OperaLocation,
		OperaParam:    s.OperaParam,
		Status:        s.Status,
		OperaTime:     s.OperaTime,
		JsonResult:    s.JsonResult,
		Remark:        s.Remark,
		LatencyTime:   s.LatencyTime,
		UserAgent:     s.UserAgent,
	}, nil
}

func (s *SysOperaLogControl) GetId() interface{} {
	return s.ID
}

type SysOperaLogGetReq struct {
	Id int `uri:"id"`
}

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

// SysOperaLogDeleteReq 功能删除请求参数
type SysOperaLogDeleteReq struct {
	Ids              []int `json:"ids"`
	common.ControlBy `swaggerignore:"true"`
}

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