import 'product_category.dart';
import 'product_draft.dart';
import 'product_image.dart';
import 'publish_status.dart';

/// Contract for fetching and managing product drafts.
abstract class ProductPublishingRepository {
  /// Returns all product drafts.
  Future<List<ProductDraft>> getProductDrafts();

  /// Publishes a draft by [id]. Returns the updated draft.
  Future<ProductDraft> publishDraft(String id);

  /// Updates the publishing status of the product identified by [id].
  ///
  /// Only [PublishStatus.draft] and [PublishStatus.published] are supported
  /// in the first pass. Implementations may throw [ArgumentError] for
  /// unsupported statuses.
  ///
  /// Returns the updated [ProductDraft] reflecting the new status.
  Future<ProductDraft> updateProductStatus(String id, PublishStatus status);

  /// Updates only the price of the product identified by [id].
  ///
  /// Returns the updated [ProductDraft] reflecting the new price.
  Future<ProductDraft> updateProductPrice(String id, double price);

  /// Updates only the name of the product identified by [id].
  ///
  /// Returns the updated [ProductDraft] reflecting the new name.
  Future<ProductDraft> updateProductName(String id, String name);

  /// Updates only the description of the product identified by [id].
  ///
  /// Returns the updated [ProductDraft] reflecting the new description.
  Future<ProductDraft> updateProductDescription(String id, String description);

  /// Updates only the category of the product identified by [id].
  ///
  /// Returns the updated [ProductDraft] reflecting the new category.
  Future<ProductDraft> updateProductCategory(String id, String category);

  // ── Stage 9C: Catalog expansion ──────────────────────────────────────────

  /// Creates a new product and returns the created [ProductDraft].
  ///
  /// [name] and [price] are required. [description], [sku], [categoryId],
  /// and [status] are optional — implementations should apply sensible
  /// defaults (e.g. [PublishStatus.draft]).
  Future<ProductDraft> createProduct({
    required String name,
    required double price,
    String description = '',
    String sku = '',
    int? categoryId,
    PublishStatus status = PublishStatus.draft,
  });

  /// Deletes the product identified by [id].
  ///
  /// [force] controls whether the product is permanently deleted (`true`) or
  /// moved to trash (`false`, WooCommerce default).
  Future<void> deleteProduct(String id, {bool force = false});

  /// Updates the images of the product identified by [id].
  ///
  /// [imageIds] is an ordered list of WooCommerce media attachment IDs.
  /// The first ID becomes the featured image (position 0).
  /// Pass an empty list to remove all images.
  ///
  /// Returns the updated [ProductDraft] reflecting the new primary image URL.
  Future<ProductDraft> updateProductImages(String id, List<int> imageIds);

  /// Returns all product categories from the store.
  Future<List<ProductCategory>> getCategories();

  /// Creates a new product category and returns the created [ProductCategory].
  ///
  /// [name] is required. [parentId] defaults to 0 (top-level category).
  Future<ProductCategory> createCategory({required String name, int parentId = 0});

  /// Updates an existing product category and returns the updated [ProductCategory].
  Future<ProductCategory> updateCategory(int categoryId, {String? name, int? parentId});

  /// Deletes the category identified by [categoryId].
  ///
  /// [force] controls whether the category is permanently deleted.
  Future<void> deleteCategory(int categoryId, {bool force = true});

  /// Returns the images attached to the product identified by [id].
  Future<List<ProductImage>> getProductImages(String id);
}
