import {
  AggregateRoot,
  Description,
  IDomainError,
  Language,
  Name,
  Quantity,
  Result,
  Slug,
  UniqueID,
  UnitPrice,
} from "@shared/contexts";
import { ArticleIdentifier } from "./ArticleIdentifier";

export interface IArticleProps {
  catalog_name: Name;
  id_article: ArticleIdentifier;
  reference: Slug;
  language: Language;
  description: Description;
  points: Quantity;
  retail_price: UnitPrice;
}

export interface IArticle {
  id: UniqueID;
  catalog_name: Name;
  id_article: ArticleIdentifier;
  reference: Slug;
  language: Language;
  description: Description;
  points: Quantity;
  retail_price: UnitPrice;
}

export class Article extends AggregateRoot<IArticleProps> implements IArticle {
  public static create(props: IArticleProps, id?: UniqueID): Result<Article, IDomainError> {
    //const isNew = !!id === false;

    // Se hace en el constructor de la Entidad
    /* if (isNew) {
      id = UniqueEntityID.create();
    }*/

    const product = new Article(props, id);

    return Result.ok<Article>(product);
  }

  private constructor(props: IArticleProps, id?: UniqueID) {
    super(props, id);
  }

  get id(): UniqueID {
    return this._id;
  }

  get catalog_name(): Name {
    return this.props.catalog_name;
  }

  get id_article(): ArticleIdentifier {
    return this.props.id_article;
  }

  get reference(): Slug {
    return this.props.reference;
  }

  get language(): Language {
    return this.props.language;
  }

  get description(): Description {
    return this.props.description;
  }

  get points(): Quantity {
    return this.props.points;
  }

  get retail_price(): UnitPrice {
    return this.props.retail_price;
  }
}
