#ifndef STAR_DETECTOR_H
#define STAR_DETECTOR_H

#include <opencv2/opencv.hpp>
#include <vector>
#include <memory>
#include <string>

/**
 * @brief The StarDetector class provides star detection functionality using StellarSolver
 *
 * This class encapsulates star detection and matching functionality that can be used
 * across different parts of the application.
 */
class StarDetector
{
    public:
        /**
         * @brief Construct a new Star Detector object
         */
        StarDetector();

        /**
         * @brief Destroy the Star Detector object
         */
        ~StarDetector();

        /**
         * @brief Detect stars in an image and create a mask
         *
         * @param image The input image
         * @return cv::Mat A mask where non-zero pixels represent detected stars
         */
        cv::Mat detectStars(const cv::Mat &image);

        /**
         * @brief Detect and match stars between two images
         *
         * @param refImage The reference image
         * @param frameImage The frame image to match against the reference
         * @param refPoints Output vector of points in the reference image
         * @param framePoints Output vector of corresponding points in the frame image
         * @return true If stars were successfully detected and matched
         * @return false If star detection or matching failed
         */
        bool detectAndMatchStars(const cv::Mat &refImage, const cv::Mat &frameImage,
                                 std::vector<cv::Point2f> &refPoints,
                                 std::vector<cv::Point2f> &framePoints);

        /**
         * @brief Set the maximum number of stars to use for matching
         *
         * @param maxStars Maximum number of stars
         */
        void setMaxStars(int maxStars);

        /**
         * @brief Get the last error message
         *
         * @return std::string The last error message
         */
        std::string getLastError() const;

        /**
         * @brief Analyze the transformation between two sets of matched points
         *
         * This method calculates and logs detailed transformation parameters including
         * translation, rotation, scaling, and determinant. It can be used to understand
         * the geometric relationship between two images.
         *
         * @param refPoints Points in the reference image
         * @param framePoints Corresponding points in the frame image
         * @param H Output homography matrix (if successful)
         * @return true If the analysis was successful
         * @return false If there were not enough points or the analysis failed
         */
        bool analyzeTransformation(const std::vector<cv::Point2f> &refPoints,
                                   const std::vector<cv::Point2f> &framePoints,
                                   cv::Mat &H);

    private:
        int m_maxStars;
        std::string m_lastError;
};

#endif // STAR_DETECTOR_H
