package cvt

import (
	"time"

	ent "github.com/tidbcloud/devops/entity/github"
	"github.com/tidbcloud/devops/models/base"
	mod "github.com/tidbcloud/devops/models/github"
)

type e2m struct{}

func (cvt e2m) PullRequest(e *ent.PullRequestInDB) *mod.GithubPullRequest {
	m := &mod.GithubPullRequest{
		ID: base.ID(e.ID),

		Location:  string(e.Location),
		Owner:     e.Owner,
		Repo:      e.Repo,
		Number:    e.Number,
		Title:     e.Title,
		Author:    e.Author,
		State:     e.State,
		CreatedAt: time.Unix(e.CreatedAt, 0),
		UpdatedAt: time.Unix(e.UpdatedAt, 0),
	}

	return m
}

func (cvt e2m) Repository(e *ent.RepositoryInDB) *mod.GithubRepository {
	m := &mod.GithubRepository{
		ID: base.ID(e.ID),

		Location:  string(e.Location),
		Owner:     e.Owner,
		Name:      e.Name,
		UpdatedAt: time.Unix(e.UpdatedAt, 0),
		PushedAt:  time.Unix(e.PushedAt, 0),
	}

	return m
}
