import "../base.api"
import "./agent.api"
import "./label_relationship.api"

type (
    // The data of whatsapp information | Whatsapp信息
    WhatsappInfo {
        BaseIDInfo

        // Status 1: normal 2: ban | 状态 1 正常 2 禁用 
        Status  *uint8 `json:"status,optional"`

        WaId  *string `json:"waId,optional"`
		WaName  *string `json:"waName,optional"`

        // 回调地址 
        Callback  *string `json:"callback,optional"`

		// 模式ID
		AgentId  *uint64 `json:"agentId,optional"`
		AgentInfo *AgentInfo `json:"agentInfo,optional"`

        // 微信账号 
        Account  *string `json:"account,optional"`

        // 手机号
        Phone  *string `json:"phone,optional"`
		Cc *string `json:"cc,optional"`

		// 号码名称
		PhoneName  *string `json:"phoneName,optional"`

		// 号码状态
		PhoneStatus  *string `json:"phoneStatus,optional"`
	
		Tokens *uint64 `json:"tokens,optional"`

		// 号码发送频率号码发送频率
		Frequency *string `json:"frequency,optional"`

		// 号码质量
		Quality *string `json:"quality,optional"`

		// 号码校验状态
		VerifyStatus *string `json:"verifyStatus,optional"`

        // 机构 ID 
        OrganizationId  *uint64 `json:"organizationId,optional"`
		OrganizationName *string `json:"organizationName,optional"`

        // 大模型服务地址 
        ApiBase  *string `json:"apiBase,optional"`

        // 大模型服务密钥 
        ApiKey  *string `json:"apiKey,optional"`

        // 白名单 
        AllowList  []ContactInfo `json:"allowList,optional"`

        // 群白名单 
        GroupAllowList  []ContactInfo `json:"groupAllowList,optional"`

        // 黑名单 
        BlockList  []ContactInfo `json:"blockList,optional"`

        // 群黑名单 
        GroupBlockList  []ContactInfo `json:"groupBlockList,optional"`
    }

	WhatsappPhoneInfo {
		Avatar  *string `json:"avatar,optional"`

		Industry  *string `json:"industry,optional"`

		Intro *string `json:"intro,optional"`

		Address  *string `json:"address,optional"`

		Email  *string `json:"email,optional"`

		Website  *string `json:"website,optional"`
	}

    // The response data of whatsapp list | Whatsapp列表数据
    WhatsappListResp {
        BaseDataInfo

        // Whatsapp list data | Whatsapp列表数据
        Data WhatsappListInfo `json:"data"`
    }

    // Whatsapp list data | Whatsapp列表数据
    WhatsappListInfo {
        BaseListInfo

        // The API list data | Whatsapp列表数据
        Data  []WhatsappInfo  `json:"data"`
    }

    // Get whatsapp list request params | Whatsapp列表请求参数
    WhatsappListReq {
        PageInfo

		// 手机号
		Phone  *string `json:"phone,optional"`

		// 号码名称
		PhoneName  *string `json:"phoneName,optional"`

		WaId  *string `json:"waId,optional"`
		OrganizationId  *uint64 `json:"organizationId,optional"`
    }

    // Whatsapp information response | Whatsapp信息返回体
    WhatsappInfoResp {
        BaseDataInfo

        // Whatsapp information | Whatsapp数据
        Data WhatsappInfo `json:"data"`
    }

	AutomationReq {
		WaId  *string `json:"waId,optional"`
		Phone  *string `json:"phone,optional"`
	}
	AutomationResp {
		BaseDataInfo

		// Whatsapp list data | Whatsapp列表数据
		Data ConversationalAutomationInfo `json:"data"`
	}
	ConversationalAutomationInfo {
		Prompts []string `json:"prompts,optional"`
		Commands []Command `json:"commands,optional"`
		Phone string `json:"phone,optional"`
		EnableWelcomeMessage bool `json:"enableWelcomeMessage,optional"`
	}
	Command {
		CommandDescription string `json:"commandDescription,optional"`
		CommandName string `json:"commandName,optional"`
	}
	SetAutomationReq {
		EnableWelcomeMessage bool `json:"enableWelcomeMessage,optional"`
		Phone string `json:"phone,optional"`
		Commands []Command `json:"commands,optional"`
		Prompts []string `json:"prompts,optional"`
		WaId string `json:"waId,optional"`
	}

	sendCodeReq {
	    Cc  *string `json:"cc"`
		Phone  *string `json:"phone"`
		WaId  *string `json:"waId"`
		Method *string `json:"method"`
		Locale *string `json:"locale"`
	}
	submitCodeReq {
	    Cc  *string `json:"cc"`
		Phone  *string `json:"phone"`
		WaId  *string `json:"waId"`
		Code *string `json:"code"`
	}
	getQrcodeReq {
		Phone  *string `json:"phone"`
		WaId  *string `json:"waId"`
	}
	getQrcodeResp {
		BaseDataInfo
		Data QrcodeListInfo `json:"data"`
	}
	QrcodeListInfo {
		BaseListInfo
		Data []Qrcode `json:"data"`
	}
	Qrcode {
		Phone string `json:"phone,optional"`
		QrdlCode string `json:"qrdlCode,optional"`
		GenerateQrImage string `json:"generateQrImage,optional"`
		PrefilledMessage string `json:"prefilledMessage,optional"`
		DeepLinkUrl string `json:"deepLinkUrl,optional"`
		QrImageUrl string `json:"qrImageUrl,optional"`
	}
	createQrcodeReq {
		Phone  string `json:"phone"`
		GenerateQrImage string `json:"generateQrImage"`
		PrefilledMessage string `json:"prefilledMessage"`
		WaId  string `json:"waId"`
	}
	updateQrcodeReq {
		Phone string `json:"phone,optional"`
		GenerateQrImage string `json:"generateQrImage,optional"`
		PrefilledMessage string `json:"prefilledMessage,optional"`
		QrdlCode string `json:"qrdlCode,optional"`
		WaId  string `json:"waId"`
	}
	removeQrcodeReq {
		Phone string `json:"phone,optional"`
		QrdlCode string `json:"qrdlCode,optional"`
		WaId  string `json:"waId"`
	}
	getBusinessReq {
		Phone  *string `json:"phone"`
		WaId  *string `json:"waId"`
	}
	getBusinessResp {
		BaseDataInfo
		Data BusinessInfo `json:"data"`
	}
	BusinessInfo {
		Vertical string `json:"vertical,optional"`
		Description string `json:"description,optional"`
		Email string `json:"email,optional"`
		Address string `json:"address,optional"`
		ProfilePictureUrl string `json:"profilePictureUrl,optional"`
		Websites []string  `json:"websites,optional"`
		About string `json:"about,optional"`
	}
	setBusinessReq {
		Phone  *string `json:"phone"`
		WaId  *string `json:"waId"`
		Vertical string `json:"vertical,optional"`
		Description string `json:"description,optional"`
		Email string `json:"email,optional"`
		Address string `json:"address,optional"`
		ProfilePictureUrl string `json:"profilePictureUrl,optional"`
		Websites []string  `json:"websites,optional"`
		About string `json:"about,optional"`
	}
	registerReq {
		Phone  *string `json:"phone"`
		WaId  *string `json:"waId"`
	}
	deregisterReq {
		Phone  *string `json:"phone"`
		WaId  *string `json:"waId"`
	}

	UpdateAgentReq {
	    Id  uint64 `json:"id"`
		AgentId  uint64 `json:"agentId"`
	}

	// 获取黑白名单列表返回体
    WhatsappAllowBlockListResp {
        BaseDataInfo

        // Wx information | Wx数据
        Data WhatsappAllowBlockListRespData `json:"data"`
    }

    // WhatsappAllowBlockListRespData
    WhatsappAllowBlockListRespData {
        // 白名单
        AllowList *string `json:"allowList,optional"`

        // 群白名单
        GroupAllowList *string `json:"groupAllowList,optional"`

        // 黑名单
        BlockList *string `json:"blockList,optional"`

        // 群黑名单
        GroupBlockList *string `json:"groupBlockList,optional"`
    }

    UpdateAllowAndBlockListReq {
        Id  uint64 `json:"id"`

        // 白名单
        AllowList *string `json:"allowList,optional"`

        // 群白名单
        GroupAllowList *string `json:"groupAllowList,optional"`

        // 黑名单
        BlockList *string `json:"blockList,optional"`

        // 群黑名单
        GroupBlockList *string `json:"groupBlockList,optional"`
    }

    UpdateAgentApiReq {
        Id  uint64 `json:"id"`

        ApiBase *string `json:"apiBase,optional"`

        ApiKey *string `json:"apiKey,optional"`
    }

	TemplateInfo {
		Category string `json:"category,optional"`
		TemplateCode string `json:"templateCode,optional"`
		Name string `json:"name,optional"`
		Language string `json:"language,optional"`
		TemplateType string `json:"templateType,optional"`
		AuditStatus string `json:"auditStatus,optional"`
		Components []TemplateComponent `json:"components,optional"`
		QualityScore string `json:"qualityScore,optional"`
		MessageSendTtlSeconds int `json:"messageSendTtlSeconds,optional"`
		Reason string `json:"reason,optional"`
	}
	TemplateSingleInfo {
		Category string `json:"category,optional"`
		TemplateCode string `json:"templateCode,optional"`
		Name string `json:"name,optional"`
		Language string `json:"language,optional"`
		TemplateType string `json:"templateType,optional"`
		AuditStatus string `json:"auditStatus,optional"`
	}
	TemplateComponent {
		Type string `json:"type,optional"`
		Url string `json:"url,optional"`
		Text string `json:"text,optional"`
		Caption string `json:"caption,optional"`
		FileName string `json:"fileName,optional"`
		Format string `json:"format,optional"`
		Buttons []TemplateButton `json:"buttons,optional"`
		ThumbUrl string `json:"thumbUrl,optional"`
		Duration int `json:"duration,optional"`
		FileType string `json:"fileType,optional"`
		Latitude string `json:"latitude,optional"`
		Longitude string `json:"longitude,optional"`
		LocationName string `json:"locationName,optional"`
		LocationAddress string `json:"locationAddress,optional"`
		AddSecretRecommendation bool `json:"addSecretRecommendation,optional"`
		CodeExpirationMinutes int `json:"codeExpirationMinutes,optional"`
		HasExpiration bool `json:"hasExpiration,optional"`
		OfferExpirationTimeMs string `json:"offerExpirationTimeMs,optional"`
	}
	TemplateButton {
		Type string `json:"type,optional"`
		Text string `json:"text,optional"`
		PhoneNumber string `json:"phoneNumber,optional"`
		Url string `json:"url,optional"`
		UrlType string `json:"urlType,optional"`
		SignatureHash string `json:"signatureHash,optional"`
		PackageName string `json:"packageName,optional"`
		AutofillText string `json:"autofillText,optional"`
		IsOptOut bool `json:"isOptOut,optional"`
		ExtendAttrs []TemplateExtendAttr `json:"extendAttrs,optional"`
		CouponCode string `json:"couponCode,optional"`
		FlowId string `json:"flowId,optional"`
		FlowAction string `json:"flowAction,optional"`
		NavigateScreen string `json:"navigateScreen,optional"`
		SupportedApps []TemplateSupportedApp `json:"supportedApps,optional"`
	}
	TemplateSupportedApp {
		SignatureHash string `json:"signatureHash,optional"`
		PackageName string `json:"packageName,optional"`
	}
	TemplateExtendAttr {
		NextTemplateCode string `json:"nextTemplateCode,optional"`
		NextTemplateName string `json:"nextTemplateName,optional"`
		NextLanguageCode string `json:"nextLanguageCode,optional"`
		Action string `json:"action,optional"`
		IntentCode string `json:"intentCode,optional"`
	}
	createTemplateReq {
		Category string `json:"category"`
		TemplateCode string `json:"templateCode"`
		Name string `json:"name"`
		Language string `json:"language"`
		TemplateType string `json:"templateType,optional"`
		AllowCategoryChange bool `json:"allowCategoryChange,optional"`
		MessageSendTtlSeconds int `json:"messageSendTtlSeconds,optional"`
	}
	listTemplateReq {
		Page int32 `json:"page"`
		pageSize int32 `json:"pageSize"`
		Name string `json:"name,optional"`
		Language string `json:"language,optional"`
		AuditStatus string `json:"auditStatus,optional"`
		TemplateType string `json:"templateType,optional"`
		Code string `json:"code,optional"`
		WaId string `json:"waId,optional"`
	}
	listTemplateResp {
		Code int    `json:"code"`
		Msg  string `json:"msg"`
		Data ListTemplate `json:"data,omitempty"`
	}
	ListTemplate {
		BaseListInfo
		Data []TemplateSingleInfo `json:"data,omitempty"`
	}
	removeTemplateReq {
		TemplateCode string `json:"templateCode,optional"`
		TemplateName string `json:"templateName,optional"`
		Language string `json:"language"`
		TemplateType string `json:"templateType,optional"`
	}
	editTemplateReq {
		Components []TemplateComponent `json:"components,optional"`
		Language string `json:"language,optional"`
		TemplateCode string `json:"templateCode,optional"`
		Category string `json:"category,optional"`
		TemplateType string `json:"templateType,optional"`
		MessageSendTtlSeconds int `json:"messageSendTtlSeconds,optional"`
		TemplateName string `json:"templateName,optional"`
	}

	getTemplateReq {
		TemplateCode string `json:"templateCode,optional"`
		Language string `json:"language"`
		TemplateType string `json:"templateType,optional"`
		TemplateName string `json:"templateName,optional"`
	}
	getTemplateResp {
		Code int    `json:"code"`
		Msg  string `json:"msg"`
		Data TemplateSingleInfo `json:"data,omitempty"`
	}
)

@server(
    jwt: Auth
    group: whatsapp
    middleware: Authority
)

service Wechat {
    // Create whatsapp information | 创建Whatsapp
    @handler createWhatsapp
    post /whatsapp/create (WhatsappInfo) returns (BaseMsgResp)

    // Update whatsapp information | 更新Whatsapp
    @handler updateWhatsapp
    post /whatsapp/update (WhatsappPhoneInfo) returns (BaseMsgResp)

    // Delete whatsapp information | 删除Whatsapp信息
    @handler deleteWhatsapp
    post /whatsapp/delete (IDsReq) returns (BaseMsgResp)

    // Get whatsapp list | 获取Whatsapp列表
    @handler getWhatsappList
    post /whatsapp/list (WhatsappListReq) returns (WhatsappListResp)

    // Get whatsapp by ID | 通过ID获取Whatsapp
    @handler getWhatsappById
    post /whatsapp (IDReq) returns (WhatsappInfoResp)

	// 发送验证码
	@handler sendWhatsappCode
	post /whatsapp/sendCode (sendCodeReq) returns (BaseMsgResp)

	// 提交验证信息
	@handler submitWhatsappCode
	post /whatsapp/submitCode (submitCodeReq) returns (BaseMsgResp)

	// 获取开场白
	@handler getAutomation
	post /whatsapp/getAutomation (AutomationReq) returns (AutomationResp)

	// 编辑开场白
	@handler setAutomation
	post /whatsapp/setAutomation (SetAutomationReq) returns (BaseMsgResp)

	// 获取二维码
	@handler getQrcode
	post /whatsapp/getQrcode (getQrcodeReq) returns (getQrcodeResp)

	// 创建二维码
	@handler createQrcode
	post /whatsapp/createQrcode (createQrcodeReq) returns (BaseMsgResp)

	// 删除二维码
	@handler removeQrcode
	post /whatsapp/removeQrcode (removeQrcodeReq) returns (BaseMsgResp)

	// 修改二维码
	@handler updateQrcode
	post /whatsapp/updateQrcode (updateQrcodeReq) returns (BaseMsgResp)

	// 获取商业信息
	@handler getBusinessInfo
	post /whatsapp/getBusinessInfo (getBusinessReq) returns (getBusinessResp)

	// 设置商业信息
	@handler setBusinessInfo
	post /whatsapp/setBusinessInfo (setBusinessReq) returns (BaseMsgResp)

	// 注册WhatsApp号码
	@handler registerPhoneNumber
	post /whatsapp/registerPhoneNumber (registerReq) returns (BaseMsgResp)

	// 取消注册WhatsApp号码
	@handler deregisterPhoneNumber
	post /whatsapp/deregisterPhoneNumber (deregisterReq) returns (BaseMsgResp)

	// Update whatsapp information | 更新Whatsapp
    @handler updateAgent
    post /whatsapp/updateAgent (UpdateAgentReq) returns (BaseMsgResp)

    // Get whatsapp allow and block list | 获取黑白名单列表
    @handler getAllowBlockList
    post /whatsapp/getAllowBlockList (IDReq) returns (WhatsappAllowBlockListResp)

    // Update whatsapp information | 更新黑白名单
    @handler updateAllowAndBlockList
    post /whatsapp/updateAllowAndBlockList (UpdateAllowAndBlockListReq) returns (BaseMsgResp)

    // Update whatsapp information | 更新黑白名单
    @handler updateAgentApi
    post /whatsapp/updateAgentApi (UpdateAgentApiReq) returns (BaseMsgResp)

	// 创建模板
	@handler createWhatsappTemplate
	post /whatsapp/createTemplate (createTemplateReq) returns (BaseDataInfo)

	// 创建模板
	@handler listWhatsappTemplate
	post /whatsapp/listTemplate (listTemplateReq) returns (listTemplateResp)

	// 删除模板
	@handler removeWhatsappTemplate
	post /whatsapp/removeTemplate (removeTemplateReq) returns (BaseDataInfo)

	// 编辑模板
	@handler editWhatsappTemplate
	post /whatsapp/editTemplate (editTemplateReq) returns (BaseDataInfo)

	// 模板详情
	@handler getWhatsappTemplate
	post /whatsapp/getTemplate (getTemplateReq) returns (getTemplateResp)
}
