Files
gridpilot.gg/core/racing/domain/value-objects/MembershipFee.ts
2026-01-16 19:46:49 +01:00

72 lines
1.7 KiB
TypeScript

/**
* Value Object: MembershipFee
* Represents membership fee configuration for league drivers
*/
import { RacingDomainValidationError } from '../errors/RacingDomainError';
import type { ValueObject } from '@core/shared/domain/ValueObject';
import type { Money } from './Money';
export type MembershipFeeType = 'season' | 'monthly' | 'per_race';
export interface MembershipFeeProps {
type: MembershipFeeType;
amount: Money;
}
export class MembershipFee implements ValueObject<MembershipFeeProps> {
readonly type: MembershipFeeType;
readonly amount: Money;
private constructor(props: MembershipFeeProps) {
this.type = props.type;
this.amount = props.amount;
}
static create(type: MembershipFeeType, amount: Money): MembershipFee {
if (!type) {
throw new RacingDomainValidationError('MembershipFee type is required');
}
if (!amount) {
throw new RacingDomainValidationError('MembershipFee amount is required');
}
return new MembershipFee({ type, amount });
}
/**
* Get platform fee for this membership fee
*/
getPlatformFee(): Money {
return this.amount.calculatePlatformFee();
}
/**
* Get net amount after platform fee
*/
getNetAmount(): Money {
return this.amount.calculateNetAmount();
}
get props(): MembershipFeeProps {
return {
type: this.type,
amount: this.amount,
};
}
/**
* Check if this is a recurring fee
*/
isRecurring(): boolean {
return this.type === 'monthly';
}
equals(other: ValueObject<MembershipFeeProps>): boolean {
const a = this.props;
const b = other.props;
return a.type === b.type && a.amount.equals(b.amount);
}
}