71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import type { ValueObject } from '@core/shared/domain/ValueObject';
|
|
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
|
|
|
export interface DecalOverrideProps {
|
|
leagueId: string;
|
|
seasonId: string;
|
|
decalId: string;
|
|
newX: number;
|
|
newY: number;
|
|
}
|
|
|
|
export class DecalOverride implements ValueObject<DecalOverrideProps> {
|
|
readonly leagueId: string;
|
|
readonly seasonId: string;
|
|
readonly decalId: string;
|
|
readonly newX: number;
|
|
readonly newY: number;
|
|
|
|
private constructor(props: DecalOverrideProps) {
|
|
this.leagueId = props.leagueId;
|
|
this.seasonId = props.seasonId;
|
|
this.decalId = props.decalId;
|
|
this.newX = props.newX;
|
|
this.newY = props.newY;
|
|
}
|
|
|
|
static create(props: DecalOverrideProps): DecalOverride {
|
|
this.validate(props);
|
|
return new DecalOverride(props);
|
|
}
|
|
|
|
private static validate(props: DecalOverrideProps): void {
|
|
if (!props.leagueId || props.leagueId.trim().length === 0) {
|
|
throw new RacingDomainValidationError('DecalOverride leagueId is required');
|
|
}
|
|
if (!props.seasonId || props.seasonId.trim().length === 0) {
|
|
throw new RacingDomainValidationError('DecalOverride seasonId is required');
|
|
}
|
|
if (!props.decalId || props.decalId.trim().length === 0) {
|
|
throw new RacingDomainValidationError('DecalOverride decalId is required');
|
|
}
|
|
if (props.newX < 0 || props.newX > 1) {
|
|
throw new RacingDomainValidationError('DecalOverride newX must be between 0 and 1');
|
|
}
|
|
if (props.newY < 0 || props.newY > 1) {
|
|
throw new RacingDomainValidationError('DecalOverride newY must be between 0 and 1');
|
|
}
|
|
}
|
|
|
|
equals(other: ValueObject<DecalOverrideProps>): boolean {
|
|
const a = this.props;
|
|
const b = other.props;
|
|
return (
|
|
a.leagueId === b.leagueId &&
|
|
a.seasonId === b.seasonId &&
|
|
a.decalId === b.decalId &&
|
|
a.newX === b.newX &&
|
|
a.newY === b.newY
|
|
);
|
|
}
|
|
|
|
get props(): DecalOverrideProps {
|
|
return {
|
|
leagueId: this.leagueId,
|
|
seasonId: this.seasonId,
|
|
decalId: this.decalId,
|
|
newX: this.newX,
|
|
newY: this.newY,
|
|
};
|
|
}
|
|
} |