package DX::Lib::FS::Action::CreateDirectory;

use aliased 'DX::Lib::FS::Fact::PathStatus';
use aliased 'DX::Lib::FS::Fact::PathStatusInfo';
use DX::Lib::FS::Guts;
use Moo;

with 'DX::Role::Action';

has path => (is => 'ro', required => 1);

has mode => (is => 'ro', predicate => 1);

sub expected_effect {
  my ($self) = @_;
  return +(path_status => PathStatus->new(
    path => $self->path,
    info => PathStatusInfo->new(
      is_directory => 1,
      mode => ($self->has_mode ? $self->mode : '')
    )
  ));
}

sub _do_run {
  my ($self) = @_;
  DX::Lib::FS::Guts->create_directory($self->path, $self->mode);
  +(path_status => $self->path);
}

1;
