using FilterCair.Server.Data;
using FilterCair.Shared.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace FilterCair.Server.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class StationController : ControllerBase
    {
        private readonly FilterCairContext _context;

        public StationController(FilterCairContext context)
        {
            _context = context;
        }

        [HttpGet("byCustomer/{customerId}")]
        public async Task<ActionResult<IEnumerable<StationModel>>> GetStationsByCustomer(int customerId)
        {
            return await _context.Stations
                .Where(s => s.CustomerId == customerId).ToListAsync();
        }

        [HttpPost]
        public async Task<IActionResult> CreateStation(StationModel station)
        { 
            _context.Stations.Add(station);
            await _context.SaveChangesAsync();
            return CreatedAtAction(nameof(GetStationsByCustomer), new { customerId = station.CustomerId }, station);
        }
    }

}
