package dto

import "github.com/jobs-scraper/internal/pkg/domain"

type JobDTO struct {
	ID          int64  `json:"id"`
	Title       string `json:"title"`
	Company     string `json:"company"`
	CompanyLink string `json:"companyLink"`
	Location    string `json:"location"`
	JobLink     string `json:"jobLink"`
	JobPostTime string `json:"jobPostTime,omitempty"`
}

func JobFromDomain(j domain.Job) JobDTO {
	var postTime string
	if j.JobPostTime != nil {
		postTime = j.JobPostTime.Format("2006-01-02")
	}
	return JobDTO{
		ID:          j.ID,
		Title:       j.Title,
		Company:     j.Company,
		CompanyLink: j.CompanyLink,
		Location:    j.Location,
		JobLink:     j.JobLink,
		JobPostTime: postTime,
	}
}

func JobsFromDomain(jobs []domain.Job) []JobDTO {
	dtos := make([]JobDTO, len(jobs))
	for i, j := range jobs {
		dtos[i] = JobFromDomain(j)
	}
	return dtos
}
