package types

import (
	appnotif "apps/backend/internal/module/appnotif/domain"
	jobDomain "apps/backend/internal/module/job/domain"
	threadsDomain "apps/backend/internal/module/threads/domain"
)

func ThreadsAccountFromModel(a *threadsDomain.Account) ThreadsAccountPublic {
	if a == nil {
		return ThreadsAccountPublic{}
	}
	return ThreadsAccountPublic{
		Id: a.ID, Username: a.Username, DisplayName: a.DisplayName,
		Connection: a.Connection, IsUsable: a.IsUsable,
		AvatarColor: a.AvatarColor, AvatarUrl: a.AvatarURL,
		ErrorMessage: a.ErrorMessage,
		SessionExpiresAt: a.SessionExpiresAt, SessionRefreshedAt: a.SessionRefreshedAt,
	}
}

func JobFromModel(j *jobDomain.Job) JobPublic {
	if j == nil {
		return JobPublic{}
	}
	return JobPublic{
		Id: j.ID, TemplateType: j.TemplateType, Status: j.Status,
		ProgressSummary: j.ProgressSummary, ProgressPercent: j.ProgressPercent,
		Error: j.Error, RefId: j.RefID, Payload: j.Payload, RunAfter: j.RunAfter,
		CreatedAt: j.CreatedAt, UpdatedAt: j.UpdatedAt, CompletedAt: j.CompletedAt,
	}
}

func NotificationFromModel(n *appnotif.Notification) NotificationPublic {
	if n == nil {
		return NotificationPublic{}
	}
	return NotificationPublic{
		Id: n.ID, Title: n.Title, Body: n.Body, Kind: n.Kind,
		RefType: n.RefType, RefId: n.RefID, ReadAt: n.ReadAt, CreatedAt: n.CreatedAt,
	}
}
