const express = require("express")
const router = express.Router()
const authRequiredMiddleware = require("../middleware/authRequired.middleware")
const authOptionalMiddleware = require("../middleware/authOptional.middleware")
const { findSellerFromLink } = require("../services/seller.service")


router.post("/from-link", authRequiredMiddleware
, async (req, res) => {
  try {
    const  sellerUrl  = req.body.url
    const Seller = await findSellerFromLink(sellerUrl)

    if (!Seller) {
      return res.json({
        sellerId: -1,
        sellerName: null,
      })
    }
    return res.json({
      id: Seller.id,
      name: Seller.name,
    })
    
  } catch (e) {
    console.error(e)
    res.status(500).json({ error: "Sunucu hatası" })
  }
})

module.exports = router
