#include "DetectorConstruction.h"
#include "G4HumanPhantomMessenger.h"

#include "G4RunManager.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithoutParameter.hh"
#include "G4UIdirectory.hh"
#include "globals.hh"

G4HumanPhantomMessenger::G4HumanPhantomMessenger(DetectorConstruction* myUsrPhtm) : myUserPhantom(myUsrPhtm){
    phantomDir = new G4UIdirectory("/phantom/");
    phantomDir->SetGuidance("Set Your Phantom.");

    phantomDir = new G4UIdirectory("/type/");
    phantomDir->SetGuidance("Set Your Particle Type");

    modelCmd = new G4UIcmdWithAString("/phantom/setPhantomModel", this);
    modelCmd->SetGuidance("Set sex of Phantom: MIRD, MIRDHead.");
    modelCmd->SetParameterName("phantomModel", true);
    modelCmd->SetDefaultValue("MIRD");
    modelCmd->SetCandidates("MIRD MIRDHead");
    modelCmd->AvailableForStates(G4State_PreInit, G4State_Idle);

    sexCmd = new G4UIcmdWithAString("/phantom/setPhantomSex", this);
    sexCmd->SetGuidance("Set sex of Phantom: Male or Female.");
    sexCmd->SetParameterName("phantomSex", true);
    sexCmd->SetDefaultValue("Female");
    sexCmd->SetCandidates("Male Female");
    sexCmd->AvailableForStates(G4State_PreInit, G4State_Idle);

    endCmd = new G4UIcmdWithoutParameter("/phantom/buildNewPhantom", this);
    endCmd->SetGuidance("Build your Phantom.");
    endCmd->AvailableForStates(G4State_PreInit, G4State_Idle);

    typeCmd = new G4UIcmdWithAString("/type/set", this);
    typeCmd->SetGuidance("Set type of Particle: TE, TP, GCR_H, GCR_He etc");
    typeCmd->SetParameterName("particleType", true);
    typeCmd->SetDefaultValue("TE");
    typeCmd->SetCandidates(
        "TE TP GCR_H GCR_He GCR_Li GCR_Be GCR_B GCR_C GCR_N GCR_O GCR_F GCR_Ne GCR_Na GCR_Mg GCR_Al GCR_Si GCR_P GCR_S "
        "GCR_Cl GCR_Ar GCR_K GCR_Ca GCR_Sc GCR_Ti GCR_V GCR_Cr GCR_Mn GCR_Fe GCR_Co GCR_Ni");
    typeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
}

G4HumanPhantomMessenger::~G4HumanPhantomMessenger() {
    delete modelCmd;
    delete sexCmd;
    delete endCmd;
    delete phantomDir;
}

void G4HumanPhantomMessenger::SetNewValue(G4UIcommand* command, G4String newValue) {
    if (command == modelCmd) {
        myUserPhantom->SetPhantomModel(newValue);
    }
    if (command == sexCmd) {
        myUserPhantom->SetPhantomSex(newValue);
    }
    if (command == endCmd) {
        G4cout << " ****************>>>> NEW PHANTOM CONSTRUCTION <<<<***************** " << G4endl;
    }
    if (command == typeCmd) {
        myUserPhantom->SetParticleType(newValue);
    }
}
