package services

import (
	"evening_detective/internal/models"
	"evening_detective/internal/services/story_service"
	"evening_detective/proto"
)

func mapTeamsToTeamAdvanced(team *models.Team) *proto.TeamAdvanced {
	return &proto.TeamAdvanced{
		Id:       team.ID,
		Name:     team.Name,
		Password: team.Password,
	}
}

func mapTeamsToTeamFull(team *models.Team) *proto.TeamFull {
	return &proto.TeamFull{
		Id:       team.ID,
		Name:     team.Name,
		Password: team.Password,
	}
}

func mapProtoTeamsToTeam(team *proto.Team) *models.Team {
	return &models.Team{
		Name: team.Name,
	}
}

func mapActionToProtoAction(action *models.Action) *proto.Action {
	return &proto.Action{
		Id:    action.ID,
		Place: action.Place,
	}
}

func mapStoryApplicationToProtoApplication(application *story_service.Application) *proto.Application {
	return &proto.Application{
		Name: application.Name,
	}
}

func mapStoryApplicationsToApplications(applications []*story_service.Application) []*models.Application {
	res := make([]*models.Application, 0, len(applications))
	for _, application := range applications {
		res = append(res, mapStoryApplicationToApplication(application))
	}
	return res
}

func mapStoryApplicationToApplication(application *story_service.Application) *models.Application {
	return &models.Application{
		Name:  application.Name,
		State: "NEW",
	}
}

func mapApplicationsToProtoApplications(applications []*models.Application) []*proto.Application {
	res := make([]*proto.Application, 0, len(applications))
	for _, application := range applications {
		res = append(res, mapApplicationToProtoApplication(application))
	}
	return res
}

func mapApplicationToProtoApplication(application *models.Application) *proto.Application {
	return &proto.Application{
		Id:    application.ID,
		Name:  application.Name,
		State: application.State,
	}
}

func mapProtoApplicationsToApplications(items []*proto.Application) []*models.Application {
	res := make([]*models.Application, 0, len(items))
	for _, item := range items {
		res = append(res, mapProtoApplicationToApplication(item))
	}
	return res
}

func mapProtoApplicationToApplication(items *proto.Application) *models.Application {
	return &models.Application{
		ID: items.Id,
	}
}
