// Code generated by sysl DO NOT EDIT.
package petshopmodel

import (
	"encoding/json"

	"github.com/anz-bank/sysl/language/go/pkg/relgom/relgomlib"
	"github.com/arr-ai/frozen"
)

const (
	employeeKey int = iota
	breedKey
	petKey
	employeeTendsPetKey
	employeeManagesEmployeeKey
	noKeysAtAllKey
)

type PetShopModel struct {
	relations frozen.Map
}

// NewPetShopModel creates a new PetShopModel.
func NewPetShopModel() PetShopModel {
	return PetShopModel{frozen.NewMap(frozen.KV(relgomlib.ModelMetadataKey, relgomlib.ModelMetadata{}))}
}

// Employee returns the model's Employee relation.
func (m PetShopModel) GetEmployee() *EmployeeRelation {
	if relation, has := m.relations.Get(employeeKey); has {
		return &EmployeeRelation{relation.(employeeRelationData), m}
	}
	return &EmployeeRelation{employeeRelationData{}, m}
}

// Breed returns the model's Breed relation.
func (m PetShopModel) GetBreed() *BreedRelation {
	if relation, has := m.relations.Get(breedKey); has {
		return &BreedRelation{relation.(breedRelationData), m}
	}
	return &BreedRelation{breedRelationData{}, m}
}

// Pet returns the model's Pet relation.
func (m PetShopModel) GetPet() *PetRelation {
	if relation, has := m.relations.Get(petKey); has {
		return &PetRelation{relation.(petRelationData), m}
	}
	return &PetRelation{petRelationData{}, m}
}

// EmployeeTendsPet returns the model's EmployeeTendsPet relation.
func (m PetShopModel) GetEmployeeTendsPet() *EmployeeTendsPetRelation {
	if relation, has := m.relations.Get(employeeTendsPetKey); has {
		return &EmployeeTendsPetRelation{relation.(employeeTendsPetRelationData), m}
	}
	return &EmployeeTendsPetRelation{employeeTendsPetRelationData{}, m}
}

// EmployeeManagesEmployee returns the model's EmployeeManagesEmployee relation.
func (m PetShopModel) GetEmployeeManagesEmployee() *EmployeeManagesEmployeeRelation {
	if relation, has := m.relations.Get(employeeManagesEmployeeKey); has {
		return &EmployeeManagesEmployeeRelation{relation.(employeeManagesEmployeeRelationData), m}
	}
	return &EmployeeManagesEmployeeRelation{employeeManagesEmployeeRelationData{}, m}
}

// NoKeysAtAll returns the model's NoKeysAtAll relation.
func (m PetShopModel) GetNoKeysAtAll() *NoKeysAtAllRelation {
	if relation, has := m.relations.Get(noKeysAtAllKey); has {
		return &NoKeysAtAllRelation{relation.(noKeysAtAllRelationData), m}
	}
	return &NoKeysAtAllRelation{noKeysAtAllRelationData{}, m}
}

// MarshalJSON implements json.Marshaler.
func (m PetShopModel) MarshalJSON() ([]byte, error) {
	b := relgomlib.NewRelationMapBuilder(m.relations)
	b.Set("Employee", employeeKey)
	b.Set("Breed", breedKey)
	b.Set("Pet", petKey)
	b.Set("EmployeeTendsPet", employeeTendsPetKey)
	b.Set("EmployeeManagesEmployee", employeeManagesEmployeeKey)
	b.Set("NoKeysAtAll", noKeysAtAllKey)
	return json.Marshal(b.Map())
}

// UnmarshalJSON implements json.Unmarshaler.
func (m *PetShopModel) UnmarshalJSON(data []byte) error {
	e := relgomlib.NewRelationMapExtractor(m.relations)
	e.Set("Employee", employeeKey, &employeeRelationData{})
	e.Set("Breed", breedKey, &breedRelationData{})
	e.Set("Pet", petKey, &petRelationData{})
	e.Set("EmployeeTendsPet", employeeTendsPetKey, &employeeTendsPetRelationData{})
	e.Set("EmployeeManagesEmployee", employeeManagesEmployeeKey, &employeeManagesEmployeeRelationData{})
	e.Set("NoKeysAtAll", noKeysAtAllKey, &noKeysAtAllRelationData{})
	relations, err := e.UnmarshalRelationDataJSON(data)
	if err == nil {
		m.relations = relations
	}
	return err
}

// newID returns a new id for the model
func (m PetShopModel) newID() (PetShopModel, uint64) {
	relations, id := relgomlib.NewID(m.relations)
	return PetShopModel{relations}, id
}
