using AsadiTools.Data;
using AsadiTools.Models;
using AsadiTools.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace AsadiTools.Pages.Shop;

public class DetailModel(AppDbContext db, CartService cart) : PageModel
{
    public Product? Product { get; private set; }

    public async Task OnGetAsync(int id)
    {
        Product = await db.Products.FindAsync(id);
    }

    public IActionResult OnPost(int productId, string nameFa, decimal price, string? sku)
    {
        cart.AddItem(new CartItem { ProductId = productId, NameFa = nameFa, Price = price, Sku = sku, Qty = 1 });
        return RedirectToPage("/Cart/Index");
    }
}
