package email_template

import "github.com/matcornic/hermes/v2"

// ProductInfo 包含產品相關的資訊，用於郵件模板中的產品展示部分
type ProductInfo struct {
	Name      string
	Link      string
	Logo      string
	Copyright string
}

// EmailBodyContent 包含郵件正文的資訊，用於生成郵件的主要內容
type EmailBodyContent struct {
	RecipientName string
	Intros        []string
	Actions       []hermes.Action
	Outros        []string
	Signature     string
}

// ForgetPasswordEmailContentParams 包含生成忘記密碼郵件所需的參數
type ForgetPasswordEmailContentParams struct {
	Product ProductInfo
	Content EmailBodyContent
}

type ForgetPasswordEmailReq struct {
	Username   string
	VerifyCode string
}

type CooperateThanksEmailReq struct {
	Username    string
	BusinessID  string
	Rewards     []RewardItem
	Country     string
	TotalAmount string
}

type RewardItem struct {
	Title   string
	Content string
	Amount  string
	//Add     string
}
type CooperateUserEmailReq struct {
	BusinessID   string `json:"business_id"`   // 開案編號
	Name         string `json:"name"`          // 聯絡人姓名
	Phone        string `json:"phone"`         // 聯絡電話
	OrgName      string `json:"org_name"`      // 團體名稱
	Email        string `json:"email"`         // 電子信箱
	TargetAmount string `json:"target_amount"` // 目標募款金額
	HasPermit    string `json:"has_permit"`    // 是否有勸募字號
	FundRequest  string `json:"fund_request"`  // 募款需求
}

const (
	nTw      = "Digimon 團隊"
	link     = "https://code.30cm.net"
	logo     = "https://true-heart-dev.s3.ap-northeast-3.amazonaws.com/f70904eb-1a29-40f7-8940-9a124f23793a.png"
	cryptoTw = "© 2025~ Digimon Inc. 版權所有"
)

// GenerateForgetPasswordEmailZHTW 生成繁體中文的忘記密碼驗證信
func GenerateForgetPasswordEmailZHTW() (string, string, error) {
	req := ForgetPasswordEmailContentParams{
		Product: ProductInfo{
			Name:      nTw,
			Link:      link,
			Logo:      logo,
			Copyright: cryptoTw,
		},
		Content: EmailBodyContent{
			RecipientName: "{{.Username}}",
			Intros: []string{
				"您收到此電子郵件是因為我們收到了針對帳戶的密碼重置請求。",
			},
			Actions: []hermes.Action{
				{
					Instructions: "請複製您的驗證碼，到網頁重置",
					InviteCode:   "{{.VerifyCode}}",
				},
			},
			Outros: []string{
				"如果您不要求重設密碼，則無需您採取進一步的措施。",
			},
			Signature: "",
		},
	}

	emailBody, err := buildForgetPasswordEmailContent(req)

	return emailBody, "Digimon 重設密碼驗證信", err
}

// GenerateBindingEmailZHTW 生成綁定帳號驗證信
func GenerateBindingEmailZHTW() (string, string, error) {
	req := ForgetPasswordEmailContentParams{
		Product: ProductInfo{
			Name:      nTw,
			Link:      link,
			Logo:      logo,
			Copyright: cryptoTw,
		},
		Content: EmailBodyContent{
			RecipientName: "{{.Username}}",
			Intros: []string{
				"您收到此電子郵件是因為我們收到了針對帳戶的Email認證請求。",
			},
			Actions: []hermes.Action{
				{
					Instructions: "請複製您的驗證碼，到網頁重置",
					InviteCode:   "{{.VerifyCode}}",
				},
			},
			Outros: []string{
				"如果您不要求重設密碼，則無需您採取進一步的措施。",
			},
			Signature: "",
		},
	}

	emailBody, err := buildForgetPasswordEmailContent(req)

	return emailBody, "Digimon 綁定信箱驗證信", err
}

// buildForgetPasswordEmailContent 根據參數生成忘記密碼郵件的產品和內容結構
func buildForgetPasswordEmailContent(params ForgetPasswordEmailContentParams) (string, error) {
	product := hermes.Product{
		Name:      params.Product.Name,
		Link:      params.Product.Link,
		Logo:      params.Product.Logo,
		Copyright: params.Product.Copyright,
	}

	body := hermes.Body{
		Name:      params.Content.RecipientName,
		Intros:    params.Content.Intros,
		Actions:   params.Content.Actions,
		Outros:    params.Content.Outros,
		Signature: params.Content.Signature,
	}

	h := hermes.Hermes{Product: product}
	email := hermes.Email{Body: body}

	return h.GenerateHTML(email)
}
