#include "ActorTLO.h"

optional<Actor> ActorTLO::GetActorById(unsigned long id) const
{
    const auto command = "Actor[" + to_string(id) + "]";
    log << "ActorTLO::GetActorById: " << command << std::endl;

    const auto actor = LSObject::FromDataParse(command);
    if (actor.has_value())
    {
        return Actor(actor.value());
    }

    return nullopt;

    // log << "ActorTLO::GetActorById: " << id << std::endl;
    // LSOBJECT *actor = nullptr;
    // const auto result = isInterface->DataParse("Actor[" + to_string(id) + "]", actor);

    // if (!actor)
    // {
    //     return nullopt;
    // }
    // return Actor(make_shared<LSObject>(actor));
}

optional<Actor> ActorTLO::GetActorByName(const std::string &name, const bool exactMatch) const
{
    stringstream query;
    query << "Actor[query, Name " << (exactMatch ? "==" : "=-") << " \"" << name << "\"]";
    const string command = query.str();
    log << "ActorTLO::GetActorByName: " << command << std::endl;

    const auto actor = LSObject::FromDataParse(command);
    if (actor.has_value())
    {
        return Actor(actor.value());
    }

    return nullopt;
}
