package domain

import (
	"math"
	"time"
)

type BaseEnnoblement struct {
	villageID  int
	newOwnerID int
	newTribeID int
	oldOwnerID int
	oldTribeID int
	points     int
	createdAt  time.Time
}

const baseEnnoblementModelName = "BaseEnnoblement"

func NewBaseEnnoblement(
	villageID int,
	newOwnerID int,
	newTribeID int,
	oldOwnerID int,
	oldTribeID int,
	points int,
	createdAt time.Time,
) (BaseEnnoblement, error) {
	if err := validateIntInRange(villageID, 1, math.MaxInt); err != nil {
		return BaseEnnoblement{}, ValidationError{
			Model: baseEnnoblementModelName,
			Field: "villageID",
			Err:   err,
		}
	}

	if err := validateIntInRange(newOwnerID, 0, math.MaxInt); err != nil {
		return BaseEnnoblement{}, ValidationError{
			Model: baseEnnoblementModelName,
			Field: "newOwnerID",
			Err:   err,
		}
	}

	if err := validateIntInRange(newTribeID, 0, math.MaxInt); err != nil {
		return BaseEnnoblement{}, ValidationError{
			Model: baseEnnoblementModelName,
			Field: "newTribeID",
			Err:   err,
		}
	}

	if err := validateIntInRange(oldOwnerID, 0, math.MaxInt); err != nil {
		return BaseEnnoblement{}, ValidationError{
			Model: baseEnnoblementModelName,
			Field: "oldOwnerID",
			Err:   err,
		}
	}

	if err := validateIntInRange(oldTribeID, 0, math.MaxInt); err != nil {
		return BaseEnnoblement{}, ValidationError{
			Model: baseEnnoblementModelName,
			Field: "oldTribeID",
			Err:   err,
		}
	}

	if err := validateIntInRange(points, 0, math.MaxInt); err != nil {
		return BaseEnnoblement{}, ValidationError{
			Model: baseEnnoblementModelName,
			Field: "points",
			Err:   err,
		}
	}

	return BaseEnnoblement{
		villageID:  villageID,
		newOwnerID: newOwnerID,
		newTribeID: newTribeID,
		oldOwnerID: oldOwnerID,
		oldTribeID: oldTribeID,
		points:     points,
		createdAt:  createdAt,
	}, nil
}

func (e BaseEnnoblement) VillageID() int {
	return e.villageID
}

func (e BaseEnnoblement) NewOwnerID() int {
	return e.newOwnerID
}

func (e BaseEnnoblement) NewTribeID() int {
	return e.newTribeID
}

func (e BaseEnnoblement) OldOwnerID() int {
	return e.oldOwnerID
}

func (e BaseEnnoblement) OldTribeID() int {
	return e.oldTribeID
}

func (e BaseEnnoblement) Points() int {
	return e.points
}

func (e BaseEnnoblement) CreatedAt() time.Time {
	return e.createdAt
}

func (e BaseEnnoblement) IsZero() bool {
	return e == BaseEnnoblement{}
}

type BaseEnnoblements []BaseEnnoblement
