Untitled
unknown
typescript
3 years ago
2.8 kB
7
Indexable
import {
FreeBet,
FreeBetPrimitives,
FreeBetStates,
FreeBetTypeProps,
} from '@lionline/games/free-bet/domain';
import { NaturalNumber, Amount, NonEmptyString, Id } from '@lionline/shared-kernel/domain';
import { TripleXFreeBet } from './triple-x-free-bet.value-object';
interface TripleXFreeBetRoundTypeProps extends FreeBetTypeProps {
name: NonEmptyString<'round'>;
config: { roundsToPlay: NaturalNumber };
}
interface TripleXFreeBetRoundTypePrimitives {
name: 'round';
config: { roundsToPlay: number };
}
export class TripleXFreeBetRound extends TripleXFreeBet<TripleXFreeBetRoundTypeProps> {
incrementRound(
numberOfRounds?: NaturalNumber | undefined,
): FreeBet<TripleXFreeBetRoundTypeProps> {
return new TripleXFreeBetRound({
id: this.props.id,
type: this.props.type,
offerId: this.props.offerId,
state: this.props.state,
actualRound: this.props.actualRound.sum(numberOfRounds ?? 1),
winAmount: this.props.winAmount,
betValue: this.props.betValue,
dueDate: this.props.dueDate,
});
}
incrementWinAmount(amount: Amount): FreeBet<TripleXFreeBetRoundTypeProps> {
return new TripleXFreeBetRound({
id: this.props.id,
type: this.props.type,
offerId: this.props.offerId,
state: this.props.state,
actualRound: this.props.actualRound,
winAmount: this.props.winAmount.sum(amount),
betValue: this.props.betValue,
dueDate: this.props.dueDate,
});
}
static fromPrimitives(props: FreeBetPrimitives<TripleXFreeBetRoundTypePrimitives>) {
return new TripleXFreeBetRound({
id: new Id({ id: props.id }),
actualRound: new NaturalNumber({ value: props.actualRound }),
betValue: new Amount({ value: props.betValue }),
dueDate: props.dueDate,
offerId: new Id({ id: props.offerId }),
state: new FreeBetStates({ state: props.state }),
type: {
name: new NonEmptyString({ value: props.type.name }),
config: { roundsToPlay: new NaturalNumber({ value: props.type.config.roundsToPlay }) },
},
winAmount: new Amount({ value: props.winAmount }),
});
}
toPrimitives(): FreeBetPrimitives<TripleXFreeBetRoundTypePrimitives> {
return {
id: this.props.id.toPrimitives(),
actualRound: this.props.actualRound.toPrimitives(),
betValue: this.props.betValue.toPrimitives(),
dueDate: this.props.dueDate,
offerId: this.props.offerId.toPrimitives(),
state: this.props.state.toPrimitives(),
type: {
name: this.props.type.name.toPrimitives(),
config: { roundsToPlay: this.props.type.config.roundsToPlay.toPrimitives() },
},
winAmount: this.props.winAmount.toPrimitives(),
};
}
}
Editor is loading...