package usecase

import (
	"context"

	"gateway/internal/model/member/domain/enum"
)

// ProfileUseCase reads and updates member profile fields (not lifecycle transitions).
type ProfileUseCase interface {
	GetByUID(ctx context.Context, req *GetMemberRequest) (*MemberDTO, error)
	GetByZitadelUserID(ctx context.Context, tenantID, zitadelUserID string) (*MemberDTO, error)
	GetByZitadelEmail(ctx context.Context, tenantID, email string) (*MemberDTO, error)
	Update(ctx context.Context, req *UpdateMemberRequest) (*MemberDTO, error)
	List(ctx context.Context, req *ListMembersRequest) (*ListMembersResponse, error)
	SetBusinessEmailVerified(ctx context.Context, tenantID, uid, email string) error
	SetBusinessPhoneVerified(ctx context.Context, tenantID, uid, phone string) error
}

// GetMemberRequest loads a member by tenant + uid.
type GetMemberRequest struct {
	TenantID string
	UID      string
}

// UpdateMemberRequest patches mutable profile fields.
type UpdateMemberRequest struct {
	TenantID    string
	UID         string
	DisplayName *string
	Avatar      *string
	Language    *string
	Currency    *string
	Phone       *string
}

// ListMembersRequest lists members within a tenant.
type ListMembersRequest struct {
	TenantID string
	Status   enum.MemberStatus
	Offset   int64
	Limit    int64
}

// ListMembersResponse is a paginated member list.
type ListMembersResponse struct {
	Items  []*MemberDTO `json:"items"`
	Total  int64        `json:"total"`
	Offset int64        `json:"offset"`
	Limit  int64        `json:"limit"`
}

// MemberDTO is the outward member profile shape.
type MemberDTO struct {
	TenantID                string            `json:"tenant_id"`
	UID                     string            `json:"uid"`
	ZitadelEmail            string            `json:"zitadel_email,omitempty"`
	ZitadelUserID           string            `json:"zitadel_user_id,omitempty"`
	DisplayName             string            `json:"display_name,omitempty"`
	Avatar                  string            `json:"avatar,omitempty"`
	Phone                   string            `json:"phone,omitempty"`
	Language                string            `json:"language,omitempty"`
	Currency                string            `json:"currency,omitempty"`
	Status                  enum.MemberStatus `json:"status"`
	Origin                  enum.MemberOrigin `json:"origin"`
	BusinessEmail           string            `json:"business_email,omitempty"`
	BusinessEmailVerified   bool              `json:"business_email_verified"`
	BusinessEmailVerifiedAt int64             `json:"business_email_verified_at,omitempty"`
	BusinessPhone           string            `json:"business_phone,omitempty"`
	BusinessPhoneVerified   bool              `json:"business_phone_verified"`
	BusinessPhoneVerifiedAt int64             `json:"business_phone_verified_at,omitempty"`
	TOTPEnrolled            bool              `json:"totp_enrolled"`
	CreateAt                int64             `json:"create_at"`
	UpdateAt                int64             `json:"update_at"`
}
