package mf_callback_ticket

import (
	"fmt"
	"strconv"
	"strings"
)

type TicketStatus int

// TicketStatus 工单状态
const (
	TicketStatusNull TicketStatus = iota // 未知状态
	TicketStatusNew
	TicketStatusInProgress
	// TicketStatusFailed
	TicketStatusNoAnswer1
	TicketStatusNoAnswer2
	// TicketStatusBusy
	// TicketStatusCancelled
	TicketStatusTimeout
	TicketStatusPending
	// TicketStatusAnswered
	// TicketStatusCompleted
	TicketStatusClosed
)

func (ts TicketStatus) Enum() string {
	switch ts {
	case TicketStatusNull:
		return "NULL"
	case TicketStatusNew:
		return "NEW"
	case TicketStatusInProgress:
		return "IN_PROGRESS"
	case TicketStatusNoAnswer1:
		return "NO_ANSWER_1"
	case TicketStatusNoAnswer2:
		return "NO_ANSWER_2"
	case TicketStatusTimeout:
		return "TIMEOUT"
	case TicketStatusPending:
		return "PENDING"
	case TicketStatusClosed:
		return "CLOSED"
	// 如果没有匹配的状态，返回未知状态
	default:
		return "UNKNOWN"
	}
}

func (ts TicketStatus) String() string {
	return fmt.Sprintf("%d", ts)
}

// ParseCallTag 将字符串转换为 CallTag 枚举类型
func ParseCallTag(s string) TicketStatus {
	if i, err := strconv.Atoi(s); err == nil {
		return TicketStatus(i)
	}
	// 如果转换失败，则按名称匹配（忽略大小写）
	switch strings.ToLower(s) {
	case "NULL":
		return TicketStatusNull
	case "NEW":
		return TicketStatusNew
	case "IN_PROGRESS":
		return TicketStatusInProgress
	case "NO_ANSWER_1":
		return TicketStatusNoAnswer1
	case "NO_ANSWER_2":
		return TicketStatusNoAnswer2
	case "TIMEOUT":
		return TicketStatusTimeout
	case "PENDING":
		return TicketStatusPending
	case "CLOSED":
		return TicketStatusClosed
	case "":
		// 如果字符串为空，则返回未知状态
		return TicketStatusNull
	default:
		// 默认返回未知状态
		return TicketStatusNull
	}
}

// CallbackTicketQuery 查询条件结构体
type CallbackTicketQuery struct {
	CallerNumber string `form:"callerNumber"`
	AgentName    string `form:"agentName"`
	Status       string `form:"status"`
	StartTime    string `form:"startTime"` // 创建时间范围-起始
	EndTime      string `form:"endTime"`   // 创建时间范围-结束
	PageNum      int    `form:"pageNum" binding:"required"`
	PageSize     int    `form:"pageSize" binding:"required"`
}

// @Description VoLTE用户信息
type CallbackTicket struct {
	TicketId     int64  `json:"ticketId" gorm:"column:ticket_id"`                        // 工单ID
	CallerNumber string `json:"callerNumber" gorm:"column:caller_number"`                // 主叫号码
	CalleeNumber string `json:"calleeNumber" gorm:"column:callee_number"`                // 被叫号码
	Status       string `json:"status" gorm:"column:status"`                             // 工单状态
	AgentName    string `json:"agentName" gorm:"column:agent_name"`                      // 坐席名称
	Comment      string `json:"comment" gorm:"column:comment"`                           // 工单备注
	MsdData      string `json:"msdData" gorm:"column:msd_data"`                          // MSD数据
	RmUid        string `json:"rmUid" gorm:"column:rm_uid"`                              // RM用户ID
	CreatedAt    int64  `json:"createdAt" gorm:"column:created_at"`                      // 创建时间
	UpdatedAt    *int64 `json:"updatedAt" gorm:"column:updated_at;autoUpdateTime:false"` // 更新时间
}

type AgentInfo struct {
	Index    int    `json:"index"`
	Name     string `json:"name"`
	Online   bool   `json:"online"`
	Email    string `json:"email"`
	Mobile   string `json:"mobile"`
	Domain   string `json:"domain"`
	Password string `json:"password"`
}

// TableName 表名称
func (*CallbackTicket) TableName() string {
	return "mf_callback_ticket"
}
