import { DefenseStatement } from './DefenseStatement';
import { SubmittedAt } from './SubmittedAt';
import { VideoUrl } from './VideoUrl';

export class ProtestDefense {
  private constructor(
    private readonly _statement: DefenseStatement,
    private readonly _videoUrl: VideoUrl | undefined,
    private readonly _submittedAt: SubmittedAt
  ) {}

  static create(statement: string, submittedAt: Date, videoUrl?: string): ProtestDefense {
    const stmt = DefenseStatement.create(statement);
    const video = videoUrl !== undefined ? VideoUrl.create(videoUrl) : undefined;
    const submitted = SubmittedAt.create(submittedAt);
    return new ProtestDefense(stmt, video, submitted);
  }

  get statement(): DefenseStatement {
    return this._statement;
  }

  get videoUrl(): VideoUrl | undefined {
    return this._videoUrl;
  }

  get submittedAt(): SubmittedAt {
    return this._submittedAt;
  }

  equals(other: ProtestDefense): boolean {
    const videoEqual = this._videoUrl === undefined && other._videoUrl === undefined ||
      (this._videoUrl !== undefined && other._videoUrl !== undefined && this._videoUrl.equals(other._videoUrl));
    return (
      this._statement.equals(other._statement) &&
      videoEqual &&
      this._submittedAt.equals(other._submittedAt)
    );
  }
}